2
$\begingroup$

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?

asked Oct 7, 2024 at 13:25
$\endgroup$
1

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.