We know that a .NET assembly is loaded at the last possible moment - when you enter a method that references a something in the foreign assembly.
When is an assembly unloaded? Is it when there are no longer any references to any classes/resources in the assembly? Is it never?
Imagine the class in the foreign assembly has a private static. The static is initialized when first needed. Presumably that static will no longer contain a value when the static variable is removed from memory.
When is an unreferenced static class removed from memory?
When is a .NET assembly unloaded?
To unload an assembly in the . NET Framework, you must unload all of the application domains that contain it. To unload an application domain, use the AppDomain. Unload method.
. NET defines a binary file format, assembly, that is used to fully describe and contain . NET programs. Assemblies are used for the programs themselves as well as any dependent libraries.
The runtime always begins probing in the application's base, which can be either a URL or the application's root directory on a computer. If the referenced assembly is not found in the application base and no culture information is provided, the runtime searches any subdirectories with the assembly name.
The AppDomain class implements a set of events that enable applications to respond when an assembly is loaded, when an application domain will be unloaded, or when an unhandled exception is thrown.
It's only unloaded when the AppDomain
that it's loaded into is unloaded, e.g. as part of a web app recycling.
Any classes within the assembly stay loaded while the assembly is loaded, so therefore they stick around until the AppDomain
is unloaded too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With