Sunday, June 9, 2013

Garbage Collection Improvements in .Net 4.5

The .Net framework 4.5 introduces a set of feature improvements to Garbage Collection, which helps it to perform more effectively. We know that the earlier versions of Garbage Collection had some limitations like performance issues when a full Garbage Collection happens, fragmentation issues with the large object heap etc. The Garbage Collection which comes with .Net 4.5 addresses some of these issues.

The following are some of the key improvements to Garbage Collection which ships with .Net 4.5
1. Background Garbage collection.

There are 2 major kinds of .Net applications.
First is the rich client applications also called win-forms applications or client server applications which have a rich UI and highly interactive. Second is the server intensive application like IIS which hosts and manages web applications which can be accessed by a huge number of users simultaneously.

.Net 4.5 introduces 2 modes of Garbage Collection to take care of these two types of applications. Background workstation Garbage Collection & Background Server Garbage Collection.

As the name indicates these new modes of Garbage Collection runs the GC in a separate background thread, which runs in parallel to the main  Client or Server applications, hence the applications need not be paused for Garbage Collection even when a full cycle Garbage Collection happens.

2. Balanced Large Object Heap allocation
Large server applications run on multiple processors simultaneously, in which case a heap is created under each processor, prior to .Net 4.5 only the small object heap was balanced between all the heaps, which the large object heap was not balanced. As a result one of the heap was loaded with more objects while the other heaps remain idle, and the heap which is overloaded will be collected frequently and leads to performance issues, now with .Net 4.5 the heap allocation is balanced and hence the number of full Garbage Collection will come down thereby improving performance.

3. Improved Large Object Heap allocation

In earlier versions, when a object instance is created the runtime scans the LOH to check for free fragment spaces to place the new object, if it finds that the fragment is not sufficient to place the object then it will not revisit the fragment for allocation in the future as a result the free fragment will remain free forever, more such free fragments get created and leads to a premature out of memory situation.

In .Net 4.5 when a the free fragments are revisited every time, even if it was not suitable during the earlier scan, thus making object allocation to LOH more effective and reduces the number of fragments in the Heap considerably. 

Search Flipkart Products:

No comments: