Skip to content

TypeDescriptor caches prevent AssemblyLoadContext from unloading #114620

Closed as duplicate of#30656
@alexey-zakharov

Description

@alexey-zakharov

TypeDescriptor caches prevent AssemblyLoadContext from unloading

ReflectTypeDescriptionProvider captures Type instance in static variable and prevents AssemblyLoadContext that owns the type from unloading.

MetadataUpdateHandler attribute is used to facilitate .NET HotReload and also used in Unity to ensure Type caches are cleared on AssemblyLoadContext unloading.
However ReflectTypeDescriptionProvider currently does not fully clear types that were requested to be removed.
While the cached properties for the type are cleared, the Type itself is kept in the _typeData ConcurrentDictionary.
This prevents AssemblyLoadContext from unloading.

The test at 0a2d601 demonstrates the AssemblyLoadContext leak.

Note: we assume that BCL libraries are safe from AssemblyLoadContext leaks (or can be fundamentally made safe)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions