Skip to content

Commit

Permalink
fix(module:core): resolve memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
arturovt committed Jul 12, 2021
1 parent 503c6f9 commit 550bb41
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions components/core/services/resize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/

import { Injectable, NgZone, Renderer2, RendererFactory2 } from '@angular/core';
import { Injectable, NgZone, OnDestroy, Renderer2, RendererFactory2 } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { auditTime, finalize } from 'rxjs/operators';

Expand All @@ -12,7 +12,7 @@ const NOOP = (): void => {};
@Injectable({
providedIn: 'root'
})
export class NzResizeService {
export class NzResizeService implements OnDestroy {
private readonly resizeSource$ = new Subject<void>();

private listeners = 0;
Expand All @@ -31,6 +31,12 @@ export class NzResizeService {
this.renderer = this.rendererFactory2.createRenderer(null, null);
}

ngOnDestroy(): void {
// Caretaker note: the `handler` is an instance property (it's not defined on the class prototype).
// The `handler` captures `this` and prevents the `NzResizeService` from being GC'd.
this.handler = NOOP;
}

subscribe(): Observable<void> {
this.registerListener();

Expand Down

0 comments on commit 550bb41

Please sign in to comment.