Skip to content

Garbage-Collector Write Barrier

A garbage-collector write barrier accompanies selected reference updates with bookkeeping that preserves a collector invariant.

Version
v1 · 2026-11-14 · History
Domain-specific #
14728
Domain group
Applied Sciences & Engineering
Origin domain
Computer Science & Software Engineering

Core Idea

A garbage-collector write barrier is bookkeeping associated with selected mutations of a managed object graph, so the collector retains the information required by its collection algorithm. It may run before or after a reference update, and may record a location, an old referent, or other collector-specific information. Its exact checks and actions depend on the collector; a compiler can sometimes prove that a particular store needs no check.[1][2]

How would you explain it like I'm…

Notes for the Cleanup Helper

Some computer programs have a helper that cleans up things the program can't reach anymore, like a tidy-up robot. When the program changes which thing points to which, a tiny note gets written down for the robot. That way the robot won't throw away something that is still being used. That little note-taking step is a write barrier.

Telling the Memory Cleaner About Changes

Many programs use a garbage collector, a helper that finds memory the program no longer needs and frees it. To do its job, the collector has to know which pieces of data point to which. A write barrier is a small extra step that runs when the program changes certain of those pointers, so the collector gets the information it needs. What the barrier writes down depends on how the collector works: it might note where the change happened or what used to be pointed to. Sometimes the compiler can prove a change doesn't need the extra step and skips it.

Bookkeeping on Reference Updates

In languages with automatic memory management, a garbage collector reclaims objects the program can no longer reach. A write barrier is bookkeeping attached to certain updates of the object graph, the web of references between objects, so the collector keeps the information its algorithm needs. It can run before or after a reference is updated, and it might record the location that was changed, the object that used to be referenced, or other collector-specific details. The exact checks and actions depend on the collector's design. Sometimes a compiler can prove that a particular store doesn't need the barrier and leave it out.

 

A garbage-collector write barrier is bookkeeping code associated with selected mutations of the managed object graph, ensuring the collector retains the information its collection algorithm requires despite the mutator changing references. Depending on the design, the barrier executes before or after a reference store and may record the updated location, the previous referent, or other collector-specific information. Its precise checks and actions are dictated by the particular collector. Because barriers impose runtime cost, compilers may elide them when they can prove a particular store requires no check.

Structural Signature

A mutator changes a reference; the collection algorithm relies on an invariant about reachability or cross-region references; the barrier maintains or records information affected by that mutation; the collector later uses that information. A false negative can hide a live reference from the relevant collection, whereas extra remembered information may increase scanning work.[1][2]

Worked Examples

Generational store check. Hölzle describes a generational collector in which the remembered set contains locations potentially holding references from older objects to younger ones. When a store creates an old-to-young reference, its location must be remembered so young objects can be collected without scanning the entire old generation. The paper notes that a compiler can omit checks for stores it can prove irrelevant.[1]

G1 concurrent marking. Oracle's 2013 description of the HotSpot G1 collector says a pre-write barrier records and marks objects belonging to the logical snapshot used in concurrent marking. The same description separately identifies a post-write barrier used to record heap changes for region remembered sets. The two actions support different parts of that collector; neither is a universal prescription for all collectors.[2]

Boundaries and Practical Use

This barrier is not a CPU write-memory barrier or fence, which orders specified memory operations under a memory model. Nor does a collector write barrier alone ensure that storage writes reach durable media in a particular order. Similar names designate different mechanisms and invariants. The necessary barrier points, optimization and synchronization must be checked against the actual collector and runtime.[3][2]

Neighborhood in Abstraction Space

Garbage-Collector Write Barrier sits in a sparse region of the domain-specific corpus (99th percentile for distinctiveness): few abstractions share its structure, so a faithful description tends to retrieve it precisely.

Family — Unclustered & Miscellaneous (3155 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-11-14

References

[1] Urs Hölzle, A Fast Write Barrier for Generational Garbage Collectors, OOPSLA '93 Workshop on Garbage Collection, October 1993, author project bibliography and abstract, https://bibliography.selflanguage.org/write-barrier.html. registry ↩a ↩b ↩c

[2] Monica Beckwith, “Garbage First Garbage Collector Tuning,” Oracle, August 2013, https://www.oracle.com/java/technologies/g1gc.html. registry ↩a ↩b ↩c ↩d

[3] Linux kernel documentation, “Ordering,” Linux Kernel Memory Model, https://docs.kernel.org/dev-tools/lkmm/docs/ordering.html. registry ↩