The garbage collector does not work continuously; it launches a single βcollectionβ at a time (which may affect multiple GC generations).
When it is called (ignored by GC.Collect() ), it is not deterministic, and I believe that this is a detail of the CLR implementation, and not part of the specification.
However, the current .NET GC will start whenever a program tries to allocate memory in a managed heap, and there is not enough free memory to do this. The collection frees up space and defragments the contents of the heap, leaving space for distribution.
Everything that survives in the Gen0 collection extends to Gen1; if there is not enough space in Gen1 for promoted items, then Gen1 is also collected. The same thing happens between Gen1 and Gen2.
source share