Most developers say:
“GC frees memory.”
That’s correct… but way too shallow to pass a real interview.
❌ 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.
👉 Most objects die young → this is why GC is optimized this way.
void CreateObjects()
{
for (int i = 0; i < 1000; i++)
{
var obj = new object(); // allocated in Gen 0
}
}❌ 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