Memory & GC interview questions
Value vs reference types, garbage collection, IDisposable.
3 questions with answers and explanations · 2 flashcards
Key ideas
- Reference-type instances live on the managed heap; value types live wherever they're declared (a local on the stack, a field inside its containing object).
- The GC is generational (Gen 0/1/2) and compacting; objects of 85,000+ bytes go to the Large Object Heap.
- The GC reclaims memory, not unmanaged resources. Implement
IDisposableand useusingfor files, sockets and DB connections. - Boxing copies a value type into a heap object; avoid it in hot paths.