Memory leaks whilst embedding python

Mark Hammond MHammond at skippinet.com.au
Mon Jul 26 20:16:46 EDT 1999


Brad Clements wrote in message <7nclk9$sg1$1 at news.clarkson.edu>...

>This, however, is going to be a giant problem for me.

Its a little problem for a few of us too.

>Because Python doesn't finalize modules, I can't clean up this memory...

This has been discussed before, and there seems to be general agreement
Python _should_ take some steps to finalize modules.

Further, although PyInit/PyFinalize leaks "static" memory, I believe
(although have not confirmed) that repeatedly calling this pair _will_
leak - although it is uncommon for apps to need to do this, it can happen.

>I'm going to have to write my own memory allocator and fake out Python and
>all add-on modules to use it, what a major pain.

Well, I would like to suggest that you help with getting Python to clear
this stuff up.  I dont think there is anything seriously hard about the
cleanup, other than a general feeling that this memory is "not a problem".
Still quite a pain, but then your efforts help mankind :-)

I dont think anyone would complain about a Python that freed up every single
memory allocation it made.  Someone just has to do it.

Re the module finalization:  Maybe a proposal could be put forward for a
module to optionally register a "module term" function (by passing a pointer
to a function at module init time - Python could stash this away somewhere,
calling it as the module is unloaded).  This would be backward compatible,
and allow modules to cleanup all their allocations - something that is
non-trivial and hacky for an extension module to do today.

You would probably find a number of people would be interested in this, and
be willing to help out with the tricky stuff once you (or someone!) takes
the lead.  I know Pythonwin and PythonCOM could benefit, and believe from
recent discussions wxPython could too.  Im sure the list is quite large.
Unfortunately for you, it seems you are the only one for which it is a
"giant problem"

Mark.







More information about the Python-list mailing list