Why does calling AppDomain.Unload doesn't result in a garbage collection?

前端 未结 2 1333
醉话见心
醉话见心 2020-12-23 22:31

When I perform a AppDomain.Unload(myDomain) I expect it to also do a full garbage collection.

According to Jeffrey Richter in \"CLR via C#\" he says that during an A

2条回答
  •  既然无缘
    2020-12-23 22:46

    1. Probably by design, but I don't understand why you want this behaviour (explicit GC.Collect). As long as the finalizers are called, the objects are removed from the finalizer queue and are ready to be garbage collected if required (the gc thread will kick in when necessary).

    2. You can probably use some nasty unmanaged allocation and some heavy interop, or code it in unmanaged c++ and then use a managed wrapper to access it through C#, but as long as you stay within the managed .Net world, no.

      It is more wise to take a second look at your architecture instead of focusing on trying to play the role of the garbage collector.

提交回复
热议问题