Is the garbage collector in .net system-wide or ap

2019-01-24 06:42发布

问题:

During discussion with my collegue, I got a doubt that the garbage collector in .net works system wide or application wide.

Means if every application having its own GC then will it effect system performance?

I am little bit confused about that.

回答1:

Each process has its own managed heap, which will be collected separately.

There's no system-wide heap, so there can be no system-wide GC.

(If you're running multiple CLRs in the same process, they'd each have their own GC too. That's a pretty rare situation though.)



回答2:

There is a Garbage Collector per process in the Workstation\Server version of the .Net runtime. GC introduces a CPU overhead per managed process.

Whether this has an impact on system performance depends on how many managed processes you have and if they are spending a lot of time collecting garbage. You can analyse how much time your process is spending collecting garbage by inspecting performance counter "% Time Spent In GC".



回答3:

Every application has its own heap and .NET runtime instance, and so it also has its own garbage collector thread.



回答4:

Have a look at this page (http://msdn.microsoft.com/en-us/library/ee787088.aspx), especially under the section The Managed Heap. That should answer your questions.