Description
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)