What is Garbage Collection?
Garbage collection is a service to freeing up memory space occupied by dead objects or objects not in use from a long time.
It is performed by 'Garbage Collector' that is nothing but a background thread. Garbage Collector is part of CLR.
Garbage Collector maintain a heap of created object for your application, it periodically checks and de-allocate memory occupied by objects no longer required (dead or not used by long time)
When it perform collection?
GC maintain a heap of objects for your application in that it categories objects in three generations,
generation 0, generation 1 & generation 2.
Newly created objects marked with generation 0. Big size newly created objects placed in Generation 1 & 2 with the assumption that they will have long life.
GC performs collection on generation 0, it releases memory from dead objects & moves alive objects to generation 1.
GC performs collection on generation 1, it releases memory from dead objects & moves alive objects to generation 2
GC performs collection on generation 2, it releases memory from dead objects.
0 Generation objects are short life object
1 Generation objects are middle life object
2 Generation objects are long life object
All short live objects resides in 0th generation so GC performs collection on 0th generation more than 1st generation, and so on..
Garbage collection is a service to freeing up memory space occupied by dead objects or objects not in use from a long time.
It is performed by 'Garbage Collector' that is nothing but a background thread. Garbage Collector is part of CLR.
Garbage Collector maintain a heap of created object for your application, it periodically checks and de-allocate memory occupied by objects no longer required (dead or not used by long time)
When it perform collection?
- Periodically
- There is predefined threshold(memory limit) for heap of your application, if memory occupied cross that limit
- When physical memory become low
GC maintain a heap of objects for your application in that it categories objects in three generations,
generation 0, generation 1 & generation 2.
Newly created objects marked with generation 0. Big size newly created objects placed in Generation 1 & 2 with the assumption that they will have long life.
GC performs collection on generation 0, it releases memory from dead objects & moves alive objects to generation 1.
GC performs collection on generation 1, it releases memory from dead objects & moves alive objects to generation 2
GC performs collection on generation 2, it releases memory from dead objects.
0 Generation objects are short life object
1 Generation objects are middle life object
2 Generation objects are long life object
All short live objects resides in 0th generation so GC performs collection on 0th generation more than 1st generation, and so on..

No comments:
Post a Comment