The garbage collector segregates the managed heap into three divisions or generations:
- Generation 0
- Generation 1
- Generation 2
The idea behind this is to optimize the application by handling long-lived and short-lived objects in memory separately. For example, if we have determined that object a is a long-term object used during the application execution, then, ideally, the garbage collector would not want to check through this object on every occasion in order to see whether it is still valid.
Instead, the garbage collector classifies short-term objects in generation 0 and long-term objects in generation 1 or 2. Only objects present in generation 0 are checked during every run of the garbage collection.
On the other hand, ...