Object generations and avoiding memory issues
There are three object generations in the .NET runtime, as follows:
- Generation 0
- Generation 1
- Generation 2
Generation 0 is the youngest generation and holds short-lived objects. Objects that are less than 80,000 bytes are generation 0 objects that get placed on the small object heap (SOH) when they are instantiated. Objects that are 80,000 bytes or larger are usually generation 2 objects and live on the large object heap (LOH). Generation 1 objects are those objects that survived generation 0 garbage collection and received a promotion to generation 1.
Generation 0 is where most of the garbage collection takes place. Objects that do not get collected when they are generation 0 will get promoted to generation 1 to make room for more generation 0 objects to be added to the heap. If generation 0 and 1 become full, then generation 1 objects are promoted to generation 2, and generation 0 objects are promoted to generation...