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
This commit is contained in:
parent
089daea98b
commit
a529d4f4f8
@ -373,12 +373,12 @@ function getAnnotation<T>(type: any, name: string): T|null {
|
|||||||
* NgModule the component belongs to. We keep the list of compiled components here so that the
|
* NgModule the component belongs to. We keep the list of compiled components here so that the
|
||||||
* TestBed can reset it later.
|
* TestBed can reset it later.
|
||||||
*/
|
*/
|
||||||
let ownerNgModule = new Map<Type<any>, NgModuleType<any>>();
|
let ownerNgModule = new WeakMap<Type<any>, NgModuleType<any>>();
|
||||||
let verifiedNgModule = new Map<NgModuleType<any>, boolean>();
|
let verifiedNgModule = new WeakMap<NgModuleType<any>, boolean>();
|
||||||
|
|
||||||
export function resetCompiledComponents(): void {
|
export function resetCompiledComponents(): void {
|
||||||
ownerNgModule = new Map<Type<any>, NgModuleType<any>>();
|
ownerNgModule = new WeakMap<Type<any>, NgModuleType<any>>();
|
||||||
verifiedNgModule = new Map<NgModuleType<any>, boolean>();
|
verifiedNgModule = new WeakMap<NgModuleType<any>, boolean>();
|
||||||
moduleQueue.length = 0;
|
moduleQueue.length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user