Garbage collection when compiling to C
- by Jules
What are the techniques of garbage collection when compiling a garbage collected language to C? I know of two:
maintain a shadow stack that saves all roots explicitly in a data structure
use a conservative garbage collector like Boehm's
The first technique is slow, because you have to maintain the shadow stack. Potentially every time a function is called, you need to save the local variables in a data structure.
The second technique is also slow, and inherently does not reclaim all garbage because of using a conservative garbage collector.
My question is: what is the state of the art of garbage collection when compiling to C. Note that I do not mean a convenient way to do garbage collection when programming in C (this is the goal of Boehm's garbage collector), just a way to do garbage collection when compiling to C.