views:

406

answers:

2

Is there

  • one Garbage Collector for an entire system
  • one instance of a garbage collector for each user that is logged in
  • one garbage collector for each running .NET application

Or is it none of the above (please explain)?

+4  A: 

There is one GC thread per .NET process and therefore one Heap per process. However, the objects are mapped to the individual AppDomains in order to provide process isolation benefits. While there can be more than one AppDomain within a process, by default there is only one per process.

Terminal Services:

What this means is that for a typical deployment of an application (called MyApp.exe) in a Terminal Services environment, the distinct instances of the .NET application that users are running will each have independent heaps and active memory management. More importantly, the Terminal Services sessions themselves represent a memory boundary of sorts given that sessions are unloaded when the user logs off (http://msdn.microsoft.com/en-us/library/aa383496(VS.85).aspx).

The following illustrates how MyApp.exe would be loaded for each Terminal Services session, and it explains some settings that could impact memory availability and performance within a session: http://blogs.technet.com/askperf/archive/2007/07/24/sessions-desktops-and-windows-stations.aspx

Deep Details:

Please refer to Jon Skeet's response here for more detail: http://stackoverflow.com/questions/241537/what-is-the-scope-of-finalizer-thread-per-application-domain-or-per-process

Esoteric Details:

Additionally, the following article explains how Microsoft is now allowing side-by-side CLR instances so that multiple versions of the CLR can be run at the same time. This applies to Silverlight specficially: http://msdn.microsoft.com/en-us/magazine/cc721609.aspx

Also, it appears that the this feature is going to be supported for all future versions of the CLR: http://blogs.msdn.com/davbr/archive/2008/11/10/new-stuff-in-profiling-api-for-upcoming-clr-4-0.aspx

EnocNRoll
Do you have a reference?
let me look that up right quick...
EnocNRoll
I'm 99% sure you are incorrect. There is one GC thread per CLR instance and hence on GC per CLR instance.
JaredPar
I had a sneaky suspicion that I did not explain it correctly, so I did some more research. Am I still off base?
EnocNRoll
You're still slightly incorrect because of the possibility of multiple CLR instances per process. It's a pretty far off corner case today though. But who knows how popular it will be in the future
JaredPar
Hm, are you referring to the CLR 4.0, as in the section "In-process side-by-side CLR instances" from http://blogs.msdn.com/davbr/archive/2008/11/10/new-stuff-in-profiling-api-for-upcoming-clr-4-0.aspx ?
EnocNRoll
It actually predates CLR 4.0. I believe it started with Silverlight 2.0
JaredPar
Hm, that's interesting and quite esoteric indeed. The following link describes this still as support for side-by-side CLRs (Desktop and CoreCLR), but they are distinct: http://msdn.microsoft.com/en-us/magazine/cc721609.aspx
EnocNRoll
Definitely escoteric, but I'm sure for someone, this is a daily pain point
JaredPar
I have updated the answer to reflect this. I appreciate your watchful eye on this one. I don't want to be wrong, even the least little bit. I want thorough info that can be referenced in the future.
EnocNRoll
IMHO, Half the fun of posting here is being wrong. Otherwise I wouldn't ever be learning anything :).
JaredPar
Don't know where you are in NC, but if you are at http://www.trinug.org/ on Wednesday, please introduce yourself.
JaredPar
That's what I love about this site, and gaining a deeper (and more accurate) understanding is what motivates me. I'm in Winston-Salem. I have not had the opportunity to attend the Triangle user group, but I have considered making the trek.
EnocNRoll
This is my first meeting so I can't give it a strong enough recomendation to warrant a trip from Winston-Salem ;)
JaredPar
Note that there is nothing to stop them changing this, indeed a common approach nowadays is the use of multiple eden (gen 0) areas, one per thread and allow the GC of that to occur inline within that thread as needed. There is still one stop the world GC thread but there's nothing enforcing that.
ShuggyCoUk
+3  A: 

There is on garbage collector per CLR instance in a process. It is possible for multiple instances of the CLR to be running in the same process but that is a pretty rare scenario. In general, there is one CLR per process.

JaredPar