Skip to content

Commit 1449c5c

Browse files
JoostKalxhub
authored andcommitted
fix(core): do not retain dynamically compiled components and modules (#42003)
The JIT compiler has a mapping from component to the owning NgModule and tracks whether a certain NgModule class has been verified; these maps causes any JIT compiled component and NgModule to be retained even if they are no longer referenced from anywhere else. This commit switches the maps to `WeakMap` to allow garbage collecting any components and NgModules that are no longer referenced elsewhere. Fixes #19997 PR Close #42003
1 parent b995201 commit 1449c5c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/core/src/render3/jit/module.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,12 @@ function getAnnotation<T>(type: any, name: string): T|null {
373373
* NgModule the component belongs to. We keep the list of compiled components here so that the
374374
* TestBed can reset it later.
375375
*/
376-
let ownerNgModule = new Map<Type<any>, NgModuleType<any>>();
377-
let verifiedNgModule = new Map<NgModuleType<any>, boolean>();
376+
let ownerNgModule = new WeakMap<Type<any>, NgModuleType<any>>();
377+
let verifiedNgModule = new WeakMap<NgModuleType<any>, boolean>();
378378

379379
export function resetCompiledComponents(): void {
380-
ownerNgModule = new Map<Type<any>, NgModuleType<any>>();
381-
verifiedNgModule = new Map<NgModuleType<any>, boolean>();
380+
ownerNgModule = new WeakMap<Type<any>, NgModuleType<any>>();
381+
verifiedNgModule = new WeakMap<NgModuleType<any>, boolean>();
382382
moduleQueue.length = 0;
383383
}
384384

0 commit comments

Comments
 (0)