Posts

Showing posts with the label 2

C# | Garbage Collection –Gen 0,1,2

Image
The CLR’s Garbage collector (GC) is a generational garbage collector, also known as ephermal garbage collector. It has three generations: Generation 0: It contains all newly constructed object which are never examined by GC. Generation 1: The CLR, when initializes, selects a budget size in kb for generation 0 . If the creation of an object causes the generation 0 to surpass its budget, garbage collection is started. The objects which are not collected in Generation 0 are moved to Generation 1 and Generation 0 is emptied. Let’s say the budget of Generation 0 is equal to size of 5 objects. So generation 0 would look like below before creation of object 6: After creation of object 6, garbage allocation gets started which deallocates the garbage objects 1, 3 and 5 and moves 2 and 4 adjacent to each other in Generation 1. The budget size of generation 1 is also selected by CLR upon initialization. Creation of object 11 causes the GC to start again which may move some more objects to generat...