There are three mode of DotNet Garbage Collection working:Workstation GC with Concurrent GC off; Workstation GC with Concurrent GC on and Server GC.On the DotNet 2.0 and later you can change it by modifying the Config file or Configuration tools,for example,using following code to enable Server GC mode:
1.Workstation GC without Concurrent: for single-CPU server, the policy-engine will adjust the working frequency of GC and useing process of Hang -> Mark and Sweep -> Compression -> Recovery to collecting the object.
2.Workstation GC with Concurrent: Concurrent GC is better than Non Concurrent GC mode in the reaction, it is the default setting of winform applications and windows services.On single-CPU computer can only use the workstation GC mode,and default setting is the Workstation GC with Concurrent.
In this mode, CLR will temporarily suspend the application when generation 0 and 1 collected, parallel processing only when generation 2 be collected,to using multi-CPU deal with Full GC phase :CLR cut Full GC phase into several
short sub-process on the thread and then thread be frozen and Full GC starting.In the time of thread be frozen outside,application is running normal.
This way usually set a large space to generation 0, so that CLR still carried out memory in generation 0 when the Full GC phase, if generation 0 space exhausted also,the application will be suspended to waiting for Full GC completed.
3.Server GC:To be used on multi-CPU computer,this mode has a high performance and efficiency.CLR will create a special GC thread for each CPU,but those gc threads can NOT working in the same time,it is NON-concurrent!So the
generation of 0,1,2 gc working will suspend the application.
There is a mode named 'background collection' In DotNet 4.0,This mode based on concurrent GC,as section 2:Full GC phase in Workstation GC with Concurrent mode, CLR still carried out in generation 0 memory allocation, if space of
generation 0 is exhausted , then the application will be suspended and waiting for Full GC completed.
The 'background collection' deal with above processing like following:during the Full GC phase collect the generation of 0,1 at the same time.The 'background collection' use a special thread to complete,the priority of this thread is lower than task of collect generation 0,1 and will suspend application too.
The 'background collection' will adjust capacity of generation 0 and 1 to reduce times of collect.
Aicken(李鸣)