← the matrixmemory

Capability — memory

Garbage collection

The runtime reclaims what you no longer reference.

Memory has to be given back, or the program runs out. Manual management worked until programs got big enough that a single forgotten free was a production incident — so languages started taking the job away instead: LISP in 1958 traced the roots, found what was reachable, and freed the rest.

The modern argument is about pauses rather than leaks. A tracing collector can find garbage in microseconds with a write barrier, or in minutes with a nursery, or not at all with a concurrent server; the language’s job is to make the choice invisible to the programmer — which is exactly why Rust, the loudest exception, is such a useful counterexample.

The trade-off

  • Collection trades pauses for leaks: a collector can make your memory usage unpredictable, which matters when you have 64MB and a latency budget.
  • Manual management trades leaks for pauses, and puts the burden on every programmer — most of whom are not thinking about it.

Where it came from

LISP, 1958 — garbage collection, recursion and conditionals arrived together, because McCarthy’s machine had no room for a programmer to manage memory by hand.