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:icon): resolve memory leak #6839

Merged
merged 1 commit into from
Jul 12, 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
16 changes: 12 additions & 4 deletions components/icon/icon.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import { DOCUMENT } from '@angular/common';
import { HttpBackend } from '@angular/common/http';
import { Inject, Injectable, InjectionToken, Optional, RendererFactory2, Self } from '@angular/core';
import { Inject, Injectable, InjectionToken, OnDestroy, Optional, RendererFactory2, Self } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { Subject } from 'rxjs';
import { Subject, Subscription } from 'rxjs';

import { IconDefinition, IconService } from '@ant-design/icons-angular';

Expand All @@ -31,10 +31,18 @@ export const DEFAULT_TWOTONE_COLOR = '#1890ff';
@Injectable({
providedIn: 'root'
})
export class NzIconService extends IconService {
export class NzIconService extends IconService implements OnDestroy {
configUpdated$ = new Subject<void>();

private iconfontCache = new Set<string>();
private subscription: Subscription | null = null;

ngOnDestroy(): void {
if (this.subscription) {
this.subscription.unsubscribe();
this.subscription = null;
}
}

normalizeSvgElement(svg: SVGElement): void {
if (!svg.getAttribute('viewBox')) {
Expand Down Expand Up @@ -81,7 +89,7 @@ export class NzIconService extends IconService {
}

private onConfigChange(): void {
this.nzConfigService.getConfigChangeEventForComponent('icon').subscribe(() => {
this.subscription = this.nzConfigService.getConfigChangeEventForComponent('icon').subscribe(() => {
this.configDefaultTwotoneColor();
this.configDefaultTheme();
this.configUpdated$.next();
Expand Down