Atlas · Details
Waste Management
Author’s note
You would think this article on garbage collection from 2004 would come across as dated. But surprisingly, GC is very much both under development and hotly debated, as it was over 20 years ago.
Nearly all languages that became popular after this post were, unsurprisingly, garbage collected, notably Golang, which was not created until three years after I posted this article. The real surprise is Rust, which has managed to keep the non-GC discussions relevant outside the niche industries like gaming where C++ still has a foothold.
The article is short, and funny in parts. I think it's still a pretty good read.
AI Notes
Triggered by two phone screens in close succession where candidates
told Steve, in identical words, that C# means "you don't have to worry
about memory." First, a defense of the abstraction: good garbage
collectors, Steve argues, are following the same trajectory compilers
followed thirty years earlier — quietly beating the people who insist
on hand-managing. Then four ways a garbage-collected program buries
itself anyway.
Allocating too many objects (you can drown any collector if you treat
allocation as free). Hard references to unused objects (the classic
cache pattern; WeakHashMap and LinkedHashMap
as the mitigations). Unreleased non-memory resources (file handles
and DB connections in finalizers that never run; Java's finally
as the right substitute for C++ stack-object cleanup). Untuned
collectors (the JVM's knobs as something working engineers should
read about).
The piece closes on two epigraphs Steve sets against each other: Ellis & Stroustrup ("C programmers think memory management is too important to be left to the computer; Lisp programmers think memory management is too important to be left to the user") and the Erik Naggum anecdote about Emacs feeling faster the day he removed the "Garbage collecting" status message.
Related listings
-
2005
Allocation Styles
The successor essay seven months later. Waste Management argues GC is a real abstraction win; Allocation Styles uses that as the bottom rung of a six-style ladder up to query and pattern-matching.
-
2004
Singleton Considered Stupid
Same month, same author voice, complementary point. Singleton is about the C-with-namespaces habit hiding inside Java; Waste Management is about the C-with-malloc habit hiding inside C# and Java.
-
2005
Practical Magic
Same instinct — let the runtime do more, you do less, then learn the runtime well enough to know when not to. Practical Magic generalises what Waste Management applies to the GC specifically.