Skip to content

Commit

Permalink
fix(module:icon): resolve memory leak (#6839)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturovt committed Jul 12, 2021
1 parent 3267571 commit bdc2a55
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions components/icon/icon.service.ts
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

0 comments on commit bdc2a55

Please sign in to comment.