[plt-scheme] Preventing GC on Scheme_Object

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Feb 9 16:43:16 EST 2008

At Sat, 9 Feb 2008 17:37:54 +0530, "Vijay Mathew" wrote:
> I have an extention for mzscheme in C++.
> 
> This is how my code looks like:
> 
> struct Widget
> {
>     Scheme_Object* callback;
> 
>     Widget() : callback(scheme_null) { }
> };
> 
> 
> Scheme_Object* callback(int argc, Scheme_Object** argv)
> {
>     Widget* w = new Widget;
>     w->callback = argv[0];
>     return scheme_true;
> }
> 
> argv[0] is a procedure assigned from scheme code.
> This is getting garbage collected when i call (collect-garbage) even though
> a reference is held in w->callback.
> I want to tell the GC about this reference.
> scheme_dont_gc_ptr(argv[0]) did not help.

scheme_dont_gc_ptr() keeps the value from being collected, but with the
3m garbage collector (which is the default in v370 and later), it
doesn't keep the object from being moved.

If the problem is that the object is being moved, then you probably
want to use scheme_malloc_immobile_box() instead of
scheme_dont_gc_ptr().

Matthew



Posted on the users mailing list.