Interview Question

What is GC and generations?

The GC reclaims unreachable managed objects and organizes survivors into generations.

💡 Concept ✅ Quick Revision 🔷 C#

Answer

The .NET garbage collector automatically reclaims managed objects that are no longer reachable. • New objects normally begin in generation 0. • Objects surviving collections can be promoted to generations 1 and 2. • Generations optimize collection frequency; they are not programmer-controlled object lifetimes.

💡 C# Example

object value = new(); Console.WriteLine(GC.GetGeneration(value));

Output

Usually 0

⚡ Quick Revision

The GC reclaims unreachable managed objects and organizes survivors into generations.