This question might be too open-ended, but I can't seem to find any resources online.
When implementing reference counting as a form of GC in a language, how do you know when to increase/decrease refcounts without explicit calls from the user? Specifically, in an AST where do you insert refcounting operations to ensure correctness?
My idea was first to only track heap and stack references, that is assignments to locals and fields of objects. But when returning a value from a function, it must be kept alive so should returns also increase refcount? But then when to decrease it? Should all temporary values be refinc'd and refdec'd? Is there an algorithm to determine when this operation is unneccessary and can be optimized away?
-
1$\begingroup$ An example of a modern algorithm: dl.acm.org/doi/10.1145/3453483.3454032 $\endgroup$Pseudonym– Pseudonym ♦2024年10月07日 23:13:15 +00:00Commented Oct 7, 2024 at 23:13