From a529d4f4f8e7db16df43fe697aed0551e75371c6 Mon Sep 17 00:00:00 2001 From: JoostK Date: Sat, 8 May 2021 17:04:39 +0200 Subject: [PATCH] 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 --- packages/core/src/render3/jit/module.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/core/src/render3/jit/module.ts b/packages/core/src/render3/jit/module.ts index 50fd3d7536..3df72f8d8e 100644 --- a/packages/core/src/render3/jit/module.ts +++ b/packages/core/src/render3/jit/module.ts @@ -373,12 +373,12 @@ function getAnnotation(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, NgModuleType>(); -let verifiedNgModule = new Map, boolean>(); +let ownerNgModule = new WeakMap, NgModuleType>(); +let verifiedNgModule = new WeakMap, boolean>(); export function resetCompiledComponents(): void { - ownerNgModule = new Map, NgModuleType>(); - verifiedNgModule = new Map, boolean>(); + ownerNgModule = new WeakMap, NgModuleType>(); + verifiedNgModule = new WeakMap, boolean>(); moduleQueue.length = 0; }