问题
What Causes Finalize Methods to Be Called ?
2 answers( of 4 ) to this question are :
The CLR is unloading an AppDomain
When an AppDomain unloads, the CLR considers nothing in the AppDomain to be a root, and a garbage collection consisting of all generations is performed.The CLR is shutting down
The CLR shuts down when a process terminates normally (as opposed to an external shutdown via Task Manager, for example).
I assume that The CLR is unloading an AppDomain
is when the program (console [exe] for example) is being closed ( by pressing close / normal end of program)
What about The CLR is shutting down
? continuing the [Exe] program analogy above :
- what does it mean ? How can I ShutDown CLR ...?
- [in the IIS world] does it mean IIS reset ?
please, can I have small explanation ?
回答1:
The AppDomain is a more granular unit than the Process. A Process can can have multiple AppDomain instances, each of which can be unloaded separately.
The CLR shutdown is the process terminating.
The AppDomain unloading is each AppDomain separately.
(although I would not personally guarantee, without checking the documentation, that all finalizers etc are executed in either case)
As an example, I use multiple AppDomain instances in a long-running self-updating windows service; when new versions are detected it pulls down the new binaries, spawns a new AppDomain, gets it running, switches future operations to the new AppDomain, and unloads the old AppDomain (when running operations have completed).
来源:https://stackoverflow.com/questions/10054866/net-clr-unloading-vs-shutdown