The Runtime Theory

Garbage Collection Cycle

How a generational garbage collector works: nursery allocation, mark-sweep, copying survivors, promotion, and the remembered set.

The Runtime Theory Team07 stages

trace / request.md

BUMP-POINTERALLOCATIONNURSERY FULL,MINOR GCMARK FROM ROOTSTRACE ANDCOPY SURVIVORSAGING ANDPROMOTIONMAJOR GC:MARK-SWEEPREMEMBEREDSET UPDATE

readyNew objects are allocated by advancing a bump pointer in the nursery — the young generation. No free-list search, no locking: a few instructions on the fast path.

Garbage collection is reclaim plus preservation: the collector must decide what is dead and what is alive, without asking the program. This diagram shows a full generational cycle: bump-pointer allocation into the nursery, a stop-the-world minor GC that marks from roots and copies survivors, aging and promotion into the old generation, and finally mark-sweep or compaction when the old generation fills. The ordering matters because generational collectors are built on one empirical fact — most objects die young — so the collector spends nearly all of its time in the small, cheap nursery and almost none in the expensive old generation. The diagram shows how the mark stack grows, which objects survive each minor cycle, and why the remembered set keeps minor collections from scanning the whole heap. The final stage shows the heap state after the cycle: live objects intact, dead ones reclaimed.