[plt-scheme] Memory management and MzScheme

From: Pedro Pinto (ppinto at cs.cmu.edu)
Date: Sat Nov 23 19:19:18 EST 2002

Thanks Anton.

I see what you are saying. But how exactly would you make a Scheme_Object
safe from collection? The result of scheme_malloc itself is collectable in
the same way (I assume) that a string is collectable...

If I am understanding you correctly you are saying that code like this:

Scheme_Object * s1 = scheme_make_string();
Scheme_Object * s2 = scheme_make_string();
.
.
.
return s1;

Is incorrect since s1 might be collected by the time control exits. But how
is that different from:

Scheme_Object **array = (Scheme_Object**) scheme_malloc (123);
Scheme_Object * s2 = scheme_make_string();
.
.
.
return array;

Why wouldn't array be collected just like s1?

I think I need to understand how the garbage collector works in MzScheme. Do
you have any references? The MzScheme manual does not seem to discuss this.

Thanks again,
-pp





> scheme_build_list would copy the string pointers into pairs, and once that
> has actually happened, your strings ought to be safe.  However, if garbage
> collection is triggered before that happens - e.g. from within
> scheme_make_string or scheme_build_list itself - the strings whose
pointers
> have not yet been copied into a Scheme structure would be fair game for
the
> garbage collector.



Posted on the users mailing list.