From 30d57fce5968779e0b67e95be33b50c5ccb0c6e5 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Tue, 12 Oct 2021 18:53:01 -0400 Subject: [PATCH] Avoid using a nested WeakMap for manager instances for a given owner. The first level WeakMap is sufficient to prevent memory leaks. The only potential value that the second level WeakMap provides is to allow us to _unload_ code during the lifetime of a single owner instance, which is really not something that we support. Having nested WeakMap's breaks some tooling around memory leak investigation that we commonly use. --- packages/@glimmer/runtime/lib/managers/index.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/@glimmer/runtime/lib/managers/index.ts b/packages/@glimmer/runtime/lib/managers/index.ts index 45a4c54b2a..754b2650b6 100644 --- a/packages/@glimmer/runtime/lib/managers/index.ts +++ b/packages/@glimmer/runtime/lib/managers/index.ts @@ -40,10 +40,7 @@ const HELPER_MANAGERS = new WeakMap< ManagerFactory | Helper> >(); -const OWNER_MANAGER_INSTANCES: WeakMap< - Owner, - WeakMap, unknown> -> = new WeakMap(); +const OWNER_MANAGER_INSTANCES: WeakMap, unknown>> = new WeakMap(); const UNDEFINED_MANAGER_INSTANCES: WeakMap, unknown> = new WeakMap(); export type ManagerFactory = (owner: O) => D; @@ -107,7 +104,7 @@ function getManagerInstanceForOwner( managers = OWNER_MANAGER_INSTANCES.get(owner); if (managers === undefined) { - managers = new WeakMap(); + managers = new Map(); OWNER_MANAGER_INSTANCES.set(owner, managers); } }