Skip to content

Guest finalizers re-populate swept per-ALC caches during unload #24075

Open

Description

@kazo0

Current behavior

ExitAlcApplication() sweeps the per-ALC static caches, but guest DependencyObject finalizers still run afterwards, during AssemblyLoadContext.Unload(), and can re-populate the shared property-system caches.

Observed via heap dump as a guest ControlExtensions attached-property entry re-rooting the dying ALC after the sweep had already run. The sweep is correct at the moment it runs; the finalizers simply run later.

Expected behavior

Once a secondary-ALC app has exited and its finalizers have drained, no shared property-system cache holds entries originating from that context, without the host having to sweep a second time.

How to fix

Either re-run (or defer) the non-default-ALC cache sweep after the unloading context's finalizers have drained, or make the caches ignore registrations originating from an ALC that is already unloading.

Host-side workaround in use: waiting for finalizers and re-invoking Application.CleanupNonDefaultAlcCaches via reflection:

await Task.Run(alc.Dispose).ConfigureAwait(false);

GC.Collect();
await DrainFinalizersAsync().ConfigureAwait(false);
await RunOnUIThreadAsync(SweepNonDefaultAlcCaches).ConfigureAwait(false);

GC.Collect();

Environment

Reproduced against Uno.Sdk.Private 6.7.0-dev.815 (artifacts/uno @ 21bf1ad6), Skia desktop (X11 + Win32) and browserwasm, hosting the three Uno.Themes sample heads as secondary-ALC guests through AlcContentHost / WindowHelper.ContentHostOverride.

Found while building the ThemesSampleApp wrapper head (unoplatform/Uno.Themes#1693); the host-side workarounds all live in GuestAppLoader.Sweeps.cs and are deleted as each fix ships.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions