|
|
Subscribe / Log in / New account

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

The trick is that you can create a cycle within an actor as much as you want, but you cannot send only part of a cycle to another actor unless the data is immutable, and you can't create a cycle between two actors. (With the exception of tag pointers, which are slightly magic; see below.)

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.


to post comments


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds