This blog post demonstrates how the garbage collector generations work.
Our simple example does the following:
- Creates an object
- Calls a method to bloat the object
- Releasing the object from memory
Between each step we check the memory used by our application and the GC generation level for our object.
We can see after the GC.Collect(0) is called the GC pushes our bigObject from the first generation (0) into the next GC generation (1).
Finally we set the object to null, meaning it’s memory can be reclaimed.