Skip to content
Sharp

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 IDisposable and use using for files, sockets and DB connections.
  • Boxing copies a value type into a heap object; avoid it in hot paths.

Questions

  1. What does a using statement (or using var declaration) guarantee?Multiple choiceEasy
  2. Which statements about the .NET garbage collector are true? Select all that apply.Select all that applyMedium
  3. A small object is still referenced for a long time. Put its life in the correct order.OrderingHard