Lesson 081

Garbage Collection

Reachability · Ref Counting · Mark & Sweep

1:00

How automatic memory managers decide what is garbage, the algorithms they use (reference counting and mark & sweep), their trade-offs, and how modern languages approach the problem.

By the end, you can

  • Explain what "reachable from the roots" means and why it defines liveness.
  • Trace which objects in a reference graph are garbage.
  • Describe how reference counting works and identify the cycle it cannot handle.
  • Explain how weak references break reference cycles.
  • Describe the two phases of mark & sweep and why it reclaims cyclic garbage.
  • Define stop-the-world pause and mark-compact, and state why collectors use them.
  • Explain the generational hypothesis and how generational collectors exploit it.
  • Identify logical memory leaks and state the fix (dropping the reference).
  • Map major languages to their memory-management strategy.
Up next in Math, Memory & Files
Questions or feedback?