Repository navigation
Description
Summary
When a host loads apps into their own collectible AssemblyLoadContexts (ALCs) and unloads them, a set of process-lifetime static caches in Uno keep strong references to the unloaded context's Assembly / Type / delegate objects. These pins prevent the collectible ALC from ever being collected after AssemblyLoadContext.Unload(), leaking the full previous-app object graph on every reload.
On WebAssembly this is especially acute: AssemblyLoadContext.Unloading is never raised, so there is no per-context callback a cache could subscribe to for self-cleanup. The only teardown seam is the host-driven cleanup hook (Application.CleanupNonDefaultAlcCaches, called from Window.CloseAlcWindow). Any static cache that outlives an app and is keyed by (or transitively references) that app's Assembly/Type/delegate must therefore be swept from that hook, or expose its own ALC-scoped removal.
This issue tracks a batch of additional pins found by rooting a disposed ALC's LoaderAllocator and following genuine managed roots (strong handle / static / stack) into it — distinct from the benign runtime residual.
Pins in scope (managed sweeps)
ResourceLoader— the static_lookupAssemblieslist (and_parsedResourcesmarkers) hold every app assembly registered viaAddLookupAssemblyfor the process lifetime.UIElementNativeRegistrar._classNames(WASM) —Dictionary<Type,int>keyed by every element type ever created, including app control types. Invisible to a desktop-only ClrMD guard.- WindowId-keyed maps —
AppWindow,ApplicationView,CoreDragDropManagerregister per-window instances with no removal path, retaining the closed window's implementation graph (and its event subscribers) for a secondary-app window. CompositionTarget.Rendering(WASM) — the static handler list retains any secondary-ALC subscriber that did not unsubscribe before unload.- Hot-reload client status history — each retained operation holds a
Type[]of the hot-reloaded (collectible) types; the history grows unbounded. PagePool(WASM) — an orphaned pool plus an eternal 30s scavenger loop, withType-keyed pooled instances.- Residual
Type-keyed statics —HtmlElementHelper._cache(WASM),FeatureConfiguration.Style.UseUWPDefaultStylesOverride.
Fix approach
Match the existing sweep pattern (Style.ClearCachesForNonDefaultAlc / DependencyProperty…RemoveNonDefaultAlcEntries): each cache gets an ALC-scoped removal wired into the cleanup hook, plus targeted self-detach / rekeying where a hook call is not reachable. Each sweep is guarded by a red/green test that asserts a collectible-ALC-keyed entry is dropped while default-ALC / framework entries are kept.
Out of scope (follow-ups)
Hot-reload delta pipeline retention; image Blob URL lifetime; FontFamilyLoader caches.
Activity
fix(alc): sweep collectible-ALC static-cache pins (WASM batch 1)
fix(alc): sweep collectible-ALC static-cache pins (WASM batch 1)