[plt-scheme] Memory management and MzScheme

From: Anton van Straaten (anton at appsolutions.com)
Date: Sat Nov 23 21:16:41 EST 2002

> Are you loading into DrScheme or MrEd, and not just MzScheme?
> Could it be that C++ is new'ing space for v?  If so, that might
> be your problem, because MrEd replaces the new operator so that
> its C++ objects are garbage collected.  Eventually, your C++
> objects will get garbage-collected too!

This is a different problem - if the replaced 'new' is used for objects that
aren't interacting directly with Scheme at all, i.e. aren't referenced by
Scheme objects, then they can become subject to collection quite easily, and
may not live very long at all, depending mostly on whether they're being
referenced by stack variables.

This wouldn't apply in the first example Pedro gave - in fact, if MrEd's
'new' were being used to create space for v, the example ought to work.
Objects will only be garbage collected if there are no references to them in
registers, the stack, or the Scheme heap.  Since the example was creating a
Scheme list and then displaying the values from within Scheme, the allocated
values ought to be safe as long as pointers to them are stored in Scheme
heap memory to start with.

BTW, instead of linking an extension with a different version of 'new', you
might consider actually exploiting the collector.  If you make sure your
object references are accessible to the collector, e.g. with appropriate use
of functions like
scheme_register_extension_global and scheme_dont_gc_ptr, then you wouldn't
have to worry about "manual" memory management.

Anton



Posted on the users mailing list.