[plt-scheme] Memory management and MzScheme

From: Ron Stanonik (stanonik at Cogsci.ucsd.edu)
Date: Mon Nov 25 11:22:49 EST 2002

On Sat, 23 Nov 2002, Anton van Straaten wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> > 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.
> 
> 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.

Thanks.  Our extension is a large existing C++ application for which
I wrote a MzScheme extension interface.  I use scheme_dont_gc_ptr for
C++ objects which my interface creates, but the application itself uses new.

I also ran into this problem with a relatively simple extension which
used a library (libfam, file alteration monitor) which was written in C++.
The library internally uses new.

Does swig do anything to help?

Thanks again,

Ron
stanonik at cogsci.ucsd.edu



Posted on the users mailing list.