5

As far as I understand in .NET we have one GC per process and one managed heap per process (it divided to SOH and LOH).

So I have a few question regarding this:

  1. If we have a few Application Domains within a process, then each domain will share the heap between others domains. Is it safe? How this separation between domains performed?

  2. When GC starts working it suspends working threads. So, if one app domain require to start GC very often it will impact on other domains that are not required garbage collection at all. And again, is there any separation for 0,1,2 generations between domains or all objects for 0 generation from different domains stored in the same 0 generation area?

  3. Why was the GC and managed heap implemented per process and not per domain?

naceka
  • 73
  • 3
  • I'm confused. I read in many places that GC heap is per process and hence shared between AppDomains. Who can shed light on this? Where can I find good explanations? – naceka Nov 12 '12 at 13:09
  • 1
    Not sure this should have been closed. GC does impact all AppDomains in the process, which seems to be what naceka is asking about. See discussion here http://stackoverflow.com/questions/15246167/does-garbage-collection-happen-at-the-process-level-or-appdomain-level/15248917?noredirect=1#comment21504895_15248917 – Tim Goodman Mar 06 '13 at 14:34
  • 1
    Best I can answer in a comment though is that it is "safe" in the sense that different AppDomains each have their own objects, but from GC's perspective these are in one heap, and yes, GC will affect all AppDomains in the process. If you don't want this, better to use separate processes. As for why it's this way, I can only speculate, but keep in mind the OS deals with processes (whereas AppDomains are a CLR construct), so when the OS allocates memory it does so to the process as whole. AppDomains exist to provide an additional level of isolation *within* the process. – Tim Goodman Mar 06 '13 at 14:49
  • 1
    To put it another way, different levels of isolation are appropriate for difference circumstances. Even separate processes still compete for system resources like processor time and memory, DB connections, network bandwidth, etc. If they need to be really, truly isolated you might run on different servers in different hosting centers in different regions... but often just separate processes is good enough, and sometimes different app domains is good enough. – Tim Goodman Mar 06 '13 at 15:02
  • 1
    @HansPassant _Your_ assumption is wrong: _GC occurs on the process level. All appdomains in the process share the same GC. GC should affect all app domains when a GC is triggered._ ([source](http://stackoverflow.com/a/15247298/146622)) – Daniel A.A. Pelsmaeker Apr 22 '13 at 16:22

0 Answers0