Really Python leaks?

Dave Cole djc at object-craft.com.au
Wed Jul 18 21:02:14 EDT 2001


>>>>> "Andrew" == Andrew Kuchling <akuchlin at mems-exchange.org> writes:

Andrew> Actually that probably isn't too surprising.  Some of the C
Andrew> code, particularly in module initializers, will allocate
Andrew> memory for a dictionary or other structure, and then not free
Andrew> it.  For earlier versions of Python, the developers had access
Andrew> to a copy of Purify; I don't know if they still do.

I know that my extension modules leak a bit due to objects which are
created when the module is imported and stick around for the lifetime
of the module.  I had not given it much thought.

Is there a way that you can trick the runtime into calling some sort
of module finaliser...

The only thing I can think of is a bit of a hack.  Create a PyCObject
with a destructor in which you free all of your internal objects.
Place a reference to the object into the module dictionary.  Is this
going to work?

Andrew> Fixing these leaks isn't a big priority, because usually the
Andrew> interpreter will only be finalized before the program exits
Andrew> anyway.  Still, if you can provide more information about
Andrew> where the leaks occur, perhaps they can be fixed.

Now that I have been reminded of issue I think I will go back and fix
my modules...  I never did feel very happy allocating those internal
objects without having a way to free them.

- Dave

-- 
http://www.object-craft.com.au



More information about the Python-list mailing list