views:

126

answers:

4

Can anybody tell me about Generation of Garbage Collector in .net ?

+1  A: 

A Microsoft article on the subject: Garbage Collection: Automatic Memory Management in the Microsoft .NET Framework

Anders Abel
+1  A: 

You don't generate the garbage collector - the garbage collecter just is.

It fires (at unpredictable times) and clears out any items that are no longer being referenced. You can "Suggest" it might want to work immediately by calling the Collect method on the Garbage Collector, which you can access through System.GC - but this does not guaruntee that it will immediately respond.

Hope that helps.

Martin Milan
@Martin: The garbage collector internally classifies memory blocks in generations, I assume that's what OP wants info about.
Anders Abel
+4  A: 

There are several optimization techniques which Garbage Collector uses. One of them uses generations of objects. Any object on the heap belongs to one of the generations:

  • Generation 0 - newly allocated objects. they were never marked for collection yet.
  • Generation 1 - objects in this generation survived one sweep.
  • Generation 2 - objects in this generation survived more than one sweep.

GC sweeps generations with higher number much less frequently.

n535
A: 

garbage collector has 3 generations 0 1 2

the highest generation is 2. In .net the garbage collector is normally invocked implicitly but you can force the GC explicitly also.

when first generations is fill i.e 0 GEN & your application wants to store some more value then this GC will invocks & check which elements are in use & which are not & delets the unused element if all the elements are in use then all the elements are transfer to little higher level i.e 1 GEN simliarly to 2 GEN when all the generations are filled & you want to store some more element then GC will throw an exception memory out of range exception .

MAS1
There's also the Large Object Heap, which is a special heap for object of at least 85000 bytes. It is handled a bit differently than the generational heaps.
Brian Rasmussen