Learn · Hidden Machines · Part IV
budding
Leave the Room, Clear the Table
Regions, arenas, borrowing, and lifetime geometry.
You will recognize a region, distinguish an arena from shared truth, and use interval overlap to decide when storage reuse is safe.
Many births, one death
A parser arena grows while parsing one document and is discarded afterward. The carrier is a region handle plus owned allocations. Allocation appends within the region; region exit reclaims all of them. Individual free operations disappear because the lifetime geometry already supplies one death.
The law is containment: every value or view published from the region must die no later than the region. Rust makes many such obligations visible in types; other runtimes may enforce them through owner-scoped APIs and generation-bound views. A checkpoint can rewind a private arena only when nothing after the checkpoint escaped.
Lifetime intervals also explain storage reuse. Two values may share a slot when their live intervals do not overlap. When ownership is unknown, tracing answers a different question—what remains reachable?—at greater runtime cost and with broader applicability.
Where the model stops
A region is wrong for independently escaping values, shared snapshots, or objects with unrelated deaths. An arena is private scratch, not a mutable database. “Allocation-free” claims must name the operation and boundary; arena growth, initialization, or output retention still allocates somewhere.
Lessons
- Shared lifetime can replace per-object reclamation.
- Borrows must remain inside the owner's lifetime.
- Non-overlapping live intervals permit storage reuse.
- Tracing is appropriate when lifetime shape is not statically owned.
Practice
- Draw live intervals for three parser phases and identify reusable slots.
- Distinguish a request arena from a cache whose entries escape requests.
- Transfer the region model to a render pass or batch import.
Part V keeps values longer but avoids recomputing them from scratch by carrying change itself.
References
- “Mads Tofte and Jean-Pierre Talpin, “Region-Based Memory Management”.” — a sound region calculus and inferred allocation/deallocation points.
- “The Rust Programming Language, “Validating References with Lifetimes”.” — lifetime relationships in Rust's type system.