Skip to content

ALC teardown does not prune SystemNavigationManager event subscriptions #24074

Open

Description

@kazo0

Current behavior

A guest (secondary-ALC) app that subscribes to the process-wide SystemNavigationManager.GetForCurrentView().BackRequested is never unsubscribed by ALC teardown. PruneCollectibleAlcEventSubscriptions does not cover this singleton's event fields (_backRequested, InternalBackRequested).

The stale handler roots the guest's Shell and, through it, the guest's entire visual tree and its ALC. Verified via heap dump.

This is reachable from ordinary app code: the Uno.Themes sample Shell subscribes to BackRequested exactly as a normal app would.

Expected behavior

ALC teardown prunes BackRequested subscriptions originating from the unloading context, and the guest visual tree becomes collectible.

How to fix

Include the SystemNavigationManager event fields in the per-ALC event subscription sweep, pruning handlers whose target (or, for static handlers, declaring module) lives in a collectible ALC:

var originAssembly = handler.Target?.GetType().Assembly ?? handler.Method.Module.Assembly;
var targetAlc = AssemblyLoadContext.GetLoadContext(originAssembly);
if (targetAlc is not null && targetAlc != AssemblyLoadContext.Default)
{
    pruned = Delegate.Remove(pruned, handler);
}

Host-side workaround in use: pruning guest-ALC handlers via reflection after unload.

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.

Activity

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