Skip to content

Commit 3650240

Browse files
authored
fix: allow TranslocoService to be garbage collected (#473)
1 parent 9ec9e71 commit 3650240

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

projects/ngneat/transloco/src/lib/transloco.service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,11 @@ export class TranslocoService implements OnDestroy {
515515

516516
ngOnDestroy() {
517517
this.subscription.unsubscribe();
518+
// Caretaker note: since this is the root provider, it'll be destroyed when the `NgModuleRef.destroy()` is run.
519+
// Cached values capture `this`, thus leading to a circular reference and preventing the `TranslocoService` from
520+
// being GC'd. This would lead to a memory leak when server-side rendering is used since the service is created
521+
// and destroyed per each HTTP request, but any service is not getting GC'd.
522+
this.cache.clear();
518523
}
519524

520525
private isLoadedTranslation(lang: string) {

0 commit comments

Comments
 (0)