C# Interview Question #72

What are GC generations in .NET?

Memory Management & Modern C# Mid-Level Intermediate

Quick Interview Answer

The .NET GC uses generations to optimize collection based on the observation that many objects have short lifetimes.

Detailed Explanation

The .NET GC uses generations to optimize collection based on the observation that many objects have short lifetimes.

Generation 0 normally contains newly allocated, short-lived objects. Objects that survive collections can be promoted to Generation 1 and later Generation 2. Generation 2 typically contains longer-lived objects.

Large objects are handled by the Large Object Heap, which has additional performance considerations.

Developers generally should not manually control generations, but understanding them helps diagnose allocation pressure and performance problems.