Skip to content

RemoveNonDefaultAlcEntries misses cross-ALC _getPropertyCache entries, pinning guest ALCs #24073

Open

Description

@kazo0

Current behavior

DependencyProperty._getPropertyCache memoizes (targetType, "ns:Owner.Property") -> DP lookups resolved from style and VSM target paths.

When a guest (secondary-ALC) style targets an attached property declared in the guest on a framework element (e.g. Button), the cache gains an entry whose key type lives in the default ALC but whose value (the DP, and its owner type) lives in the guest ALC.

NameToPropertyDictionary.RemoveNonDefaultAlcEntries checks only the key's ALC, so the entry survives ExitAlcApplication()'s sweep and roots the guest's LoaderAllocator. The collectible ALC can then never be collected.

Verified with dotnet-dump gcroot: the retention path enters through this cache entry.

Expected behavior

After a secondary-ALC app unloads, no entry in _getPropertyCache references a DP whose owner type lives in the unloading context, and the guest's LoaderAllocator becomes collectible.

How to fix

Also check the cached DP value's owner-type ALC in RemoveNonDefaultAlcEntries, or clear this cache wholesale on ALC teardown. It is a pure memoization over DependencyPropertyRegistry, so clearing it is safe and it repopulates on demand.

Host-side workaround in use: clearing _getPropertyCache 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