Cyclic references in garbage collection
Cyclic references in garbage collection
Posted Jan 3, 2025 17:09 UTC (Fri) by daroc (editor, #160859)In reply to: Cyclic references in garbage collection by epa
Parent article: Preventing data races with Pony
So imagine that I have mutually referential objects A and B.
If I have an isolated pointer to the whole cycle, I can send the whole cycle to another actor. But A and B can't directly reference each other with isolated pointers, because then either they would immediately be garbage, or the isolated pointers wouldn't be unique.
For value pointers, the objects are immutable, so sending B to another actor doesn't cause problems — from the first actor's point of view, it just pins the cycle as a garbage collection root until the second actor is done with it.
For reference, box, and transition pointers, the objects can't be sent to another actor.
For tag pointers, the runtime pulls a little bit of magic to detect cycles at the same time it detects dead actors; you're correct that you can actually have between-actor cycles using tag pointers, and this complicates things. For the purposes of garbage collection, though, they really are just treated as collection roots, with cycles getting cleaned up by the separate system that reaps dead actors.