Wednesday, January 22, 2014

.Net Garbage Collection

Memory management is the main concern for any application whether application is window based or web based. In .Net, CLR has garbage collector that executes as a part of our program and responsible for reclaiming the memory of no longer used objects. Garbage collector free the memory for objects that are no longer referenced and keeps the memory for future allocations.

Importan Points,

All objects in the heap are allocated from one connecting range of memory address and heap is divided into generations so that it is easy to eliminate the garbage objects by looking at only a small fraction of the heap.

01.Generation 0
This is the youngest generation and contains the newly created objects. Generation 0 has short-lived objects and collected frequently. The objects that survive the Generation 0 are promoted to Generation 1.

Example : A temporary object.

02.Generation 1
This generation contains the longer lived objects that are promoted from generation 0. The objects that survive the Generation 1 are promoted to Generation 2. Basically this generation serves as a buffer between short-lived objects and longest-lived objects.

03.Generation 2
This generation contains the longest lived objects that are promoted from generation 1 and collected infrequently.

Example : An object at application level that contains static data which is available for the duration of the process.








No comments:

Post a Comment

Abstract Factory Vs Factory Method

Abstract Factory Provides an interface for creating families of related or dependent objects without specifying their concrete classes ...