Skip to content

Commit

Permalink
fix(core): do not retain dynamically compiled components and modules (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
JoostK authored and alxhub committed May 10, 2021
1 parent bd2e66c commit 5bb7c0e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/core/src/render3/jit/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,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
* TestBed can reset it later.
*/
let ownerNgModule = new Map<Type<any>, NgModuleType<any>>();
let verifiedNgModule = new Map<NgModuleType<any>, boolean>();
let ownerNgModule = new WeakMap<Type<any>, NgModuleType<any>>();
let verifiedNgModule = new WeakMap<NgModuleType<any>, boolean>();

export function resetCompiledComponents(): void {
ownerNgModule = new Map<Type<any>, NgModuleType<any>>();
verifiedNgModule = new Map<NgModuleType<any>, boolean>();
ownerNgModule = new WeakMap<Type<any>, NgModuleType<any>>();
verifiedNgModule = new WeakMap<NgModuleType<any>, boolean>();
moduleQueue.length = 0;
}

Expand Down

0 comments on commit 5bb7c0e

Please sign in to comment.