Tensions in Practice: Prompt reclamation in tension with cycle detection¶
Memory ownership · a disconnected cycle
The root can reach object L. Objects A and B refer only to each other, so no legitimate access starts a path to either. Plain reference counting still sees one incoming reference at each object and retains both. A tracing pass can discover that neither is reachable, but the stop-the-world tracer chosen here pauses application work while it makes that decision.
Reclaim incrementally
Release resources promptly as references disappear without a full graph pause on every release.
Reclaim unreachable cycles
Recover resources even when they continue to refer to each other.
Why these aims pull against each other
A positive incoming count is not the same as a path from a declared root. Testing the latter requires a correct reachability computation while the reference graph is controlled.
Choose an arrangement to see what changes and what remains difficult.
Qualitative paths and conditions, not measured costs, timings or performance guarantees.
What this choice protects
What it costs
When it fits
Compare the arrangements
Count references
Update each object’s count as references change, reclaiming objects when their counts reach zero.
- What it protects
- Acyclic objects can be reclaimed incrementally when the last reference disappears.
- What it costs
- A and B retain each other despite being unreachable; this plain method needs additional cycle handling.
- When it fits
- Fits acyclic ownership structures or a design where separate cycle handling covers the remaining cases.
Illustration note: The picture isolates plain reference counting. Weak references and cycle collectors are additional mechanisms, not silently assumed.
Trace from roots
Pause reference mutation, trace from the declared roots, and reclaim unmarked objects.
- What it protects
- The A–B cycle is collectible because no root reaches either member.
- What it costs
- The selected stop-the-world pass interrupts application work and must correctly enumerate all roots and edges.
- When it fits
- Fits tolerable collection pauses and a runtime with an accurate root set and complete reference tracking.
Illustration note: This is one paused tracing implementation. Tracing in general need not use a single full pause; concurrent and incremental collectors require additional machinery.
What this illustration does—and does not—establish
Garbage Collection: Tracing versus Reference Counting supplies the cycle distinction. The cost excerpt and explicit chosen tracer avoid the source’s overbroad implication that every tracing collector necessarily pauses the whole system.
- A missing legitimate root makes either claimed safety boundary unreliable.
- The dashed cycle in the second drawing is the former relation, not usable pointers after reclamation.
- External effects such as file handles require their own release obligations; memory reachability alone does not settle them.
Source entries
Garbage Collection
Garbage Collection: Tracing versus Reference Counting supplies the conflict examined here.
Tracing versus Reference Counting
counting is incremental and prompt but cannot reclaim cycles unaided.
Reclamation Throughput versus Pause Cost
Collection trades steady human attention for an occasional automated pass whose cost scales with live-data size, but the pass itself competes with productive work — a long stop-the-world sweep stalls the system it serves.