Skip to content

Commit 5bb7c0e

Browse files
JoostKalxhub
authored andcommitted
fix(core): do not retain dynamically compiled components and modules (angular#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 angular#19997 PR Close angular#42003
1 parent bd2e66c commit 5bb7c0e

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
@@ -375,12 +375,12 @@ function getAnnotation<T>(type: any, name: string): T|null {
375375
* NgModule the component belongs to. We keep the list of compiled components here so that the
376376
* TestBed can reset it later.
377377
*/
378-
let ownerNgModule = new Map<Type<any>, NgModuleType<any>>();
379-
let verifiedNgModule = new Map<NgModuleType<any>, boolean>();
378+
let ownerNgModule = new WeakMap<Type<any>, NgModuleType<any>>();
379+
let verifiedNgModule = new WeakMap<NgModuleType<any>, boolean>();
380380

381381
export function resetCompiledComponents(): void {
382-
ownerNgModule = new Map<Type<any>, NgModuleType<any>>();
383-
verifiedNgModule = new Map<NgModuleType<any>, boolean>();
382+
ownerNgModule = new WeakMap<Type<any>, NgModuleType<any>>();
383+
verifiedNgModule = new WeakMap<NgModuleType<any>, boolean>();
384384
moduleQueue.length = 0;
385385
}
386386

0 commit comments

Comments
 (0)