-
Notifications
You must be signed in to change notification settings - Fork 474
Description
.NET Core 3.0 introduces support for unloading assemblies after loading them into a custom AssemblyLoadContext
via the new Unload
method and constructor with isCollectible
parameter. The custom AssemblyLoadContext
is set up to only contain the assemblies you want with everything else being in the default context. Obviously this is a .NET Core 3.0 feature, and .NET Framework will never support it; .NET Standard also does not define System.Runtime.Loader
classes. Unfortunately it looks like dynamic assemblies were missed (https://github.com/dotnet/corefx/issues/38426) and support for them won't make the cut for .NET Core 3.0.
- https://docs.microsoft.com/en-us/dotnet/standard/assembly/unloadability-howto
- https://github.com/dotnet/samples/tree/master/core/tutorials/Unloading
- https://github.com/dotnet/coreclr/issues/552
.NET Framework 4.0 introduced AssemblyBuilderAccess.RunAndCollect
which allows dynamic assemblies to be garbage collected when no reference is held. RunAndCollect
has a whole heap of restrictions on what can be emitted into the assembly (e.g. no COM interop), but I think we could fairly trivially add opt-in for this per ModuleScope
to make it disposable.
I don't know how useful this feature would actually be since we don't get any requests for it, but logging this as an enhancement to raise the topic since it is possible. It sounds like it RunAndCollect
could be helpful for #472.