> To retain a safe reference to a Scheme-level object from C > can only be done via GC-roots, otherwise the reference will be lost on > the next GC.
What happens if your Scheme-level object is only referenced (through a GC-root) from the C-level object and the C-level object is *only* referenced from the Scheme-level object? Do we not leak memory? > Of course, any references to C data (which may refer to Scheme data > via GC-roots) are not seen by the GC or finalization mechanism, so > will not "loop" into that direction. You mean "any references inside C data", right? I see what you're saying. I think we should have some structure "weaker" than GC-root that serves this purpose of allowing C-level objects to reference Scheme-level objects but which doesn't have the "never GC this" semantics. The GC-roots should use this structure but also have the stronger property of never being collected, even if they are not reachable from Scheme-level objects. The way I think it would make sense to do this would be the following. If I receive a c-pointer to some structure that can hold a pointer, I use a record that wraps the c-pointer and *always* refer to it through the structure. Then, when I set something inside of the c-pointer to point to a Scheme-object foo, I: 1. Create a new instance of the structure-weaker-than-a-GC-root, set it to foo and store a pointer to that in the C data. 2. Set an attribute in the record to foo, so that the GC code will know that it can't collect foo yet. What do you think? Alejo. http://azul.freaks-unidos.net/ _______________________________________________ Chicken-users mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/chicken-users
