Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module:core): resolve memory leak #6852

Merged
merged 1 commit into from
Oct 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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