Python and Boehm-Demers GC, I have code.

Ovidiu Predescu ovidiu at cup.hp.com
Mon Jul 19 20:01:38 EDT 1999


Neil Schemenauer wrote:

> I have added the Boehm-Demers garbage collector to Python and it
> works well!

Great work! However, this is not enough, there are more things to do
;-/!

More than a year ago I've added support for the Boehm's collector to
Objective-C, an object oriented language based on C, and two libraries
written in Objective-C that use reference counting as a memory tracking
policy.

What I found is that I needed to introduce weak references in these
libraries, otherwise I would have objects alive without being used
anymore by the code. The reason were two places in these libraries where
objects were kept in a global table. Having references to objects from
this table prevented the objects from being collected, even if you drop
the references to the objects from the rest of your code. The
alternative is to require the programmer to remove the references from
these global tables when he is no longer interested in keeping the
objects alive, but this is error-prone and defeats the whole purpose of
automatic garbage collection.

I don't know exactly if there are any modules in Python that keep track
of objects in global variables but if this is the case you may need to
implement something like that.

One of the libraries I'm referring to is libFoundation and you can find
it at:

http://www.geocities.com/SiliconValley/Monitor/7464/libFoundation/

The interesting piece you may want to look at is GarbageCollector.m. It
defines a way to register observers for the finalization of other
objects. The registering is done programmatically, by interested objects
(like for example the NSNotificationCenter, which allows interested
objects to be informed when a particular event is posted by another
object).

The support for weak pointers in the Objective-C runtime was done using
the typed-memory facility of the Boehm's collector. Take a look at a
description of how it works on:

http://www.geocities.com/SiliconValley/Monitor/7464/Objective-C/

If you're interested in the sources of the runtime, get a recent
snapshot of EGCS and look in the libobjc directory.


Have fun,
-- 
Ovidiu Predescu <ovidiu at cup.hp.com>
http://andromeda.cup.hp.com/  (inside HP's firewall only)
http://www.geocities.com/SiliconValley/Monitor/7464/




More information about the Python-list mailing list