Skip to content

Commit

Permalink
fix(cdk): DirectiveStylesService fix ssr memory leak (#6288)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirpotekhin authored Dec 22, 2023
1 parent e8ac4ea commit 799e7d6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions projects/cdk/services/directive-styles.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {
ComponentFactoryResolver,
ComponentRef,
Inject,
Injectable,
INJECTOR,
Injector,
OnDestroy,
Type,
} from '@angular/core';

Expand All @@ -13,8 +15,8 @@ import {
@Injectable({
providedIn: 'root',
})
export class TuiDirectiveStylesService {
private readonly map = new Map<Type<unknown>, unknown>();
export class TuiDirectiveStylesService implements OnDestroy {
private readonly map = new Map<Type<unknown>, ComponentRef<unknown>>();

constructor(
@Inject(ComponentFactoryResolver)
Expand All @@ -30,4 +32,8 @@ export class TuiDirectiveStylesService {
);
}
}

ngOnDestroy(): void {
this.map.forEach(value => value.destroy());
}
}

0 comments on commit 799e7d6

Please sign in to comment.