Garbage Collection in .NET (Interview Guide)

Most developers say:
“GC frees memory.”
That’s correct… but way too shallow to pass a real interview.

What is Garbage Collection in .NET?

❌ Bad answer

It automatically frees unused memory.

✅ Senior answer

Garbage Collection (GC) is an automatic memory management system that reclaims memory occupied by objects that are no longer referenced by the application.
It optimizes performance using a generational model and runs periodically to balance memory usage and CPU cost.

How Garbage Collection works

Generational model (very important)

👉 Most objects die young → this is why GC is optimized this way.

Example

void CreateObjects()
{
    for (int i = 0; i < 1000; i++)
    {
        var obj = new object(); // allocated in Gen 0
    }
}

Common mistakes

❌ Forcing GC manually

GC.Collect();

This can hurt performance. Let the runtime decide.

❌ Memory leak misconception

GC does not prevent memory leaks if references are still held.

Want to practice explaining this like a senior?

Practice Now
← See more .NET interview questions