Memory problem (possibly involves interpreter)

Bryn Keller xoltar at starship.python.net
Thu Apr 18 19:59:29 EDT 2002


Hi folks,

I have an application which uses unexpectedly large amounts of memory,
and then doesn't free as much of it as it should. It's a GUI
application, and when I show a new (instance of a) window, the memory
usage as reported by Task Manager (this is NT4/sp6a) climbs by a
certain amount, say 340K. Close the window and the memory drops by
108K. Now, I'd understand that this is just garbage collection at
work, or a memory leak in my code, and wouldn't bother everyone on the
list with it, if it weren't for these facts:

1. These numbers stay roughly the same no matter how many times you
open and close the window. So opening and closing the same (class of)
window 100 times took me from 24356K to 67456K. This would seem to
indicate there is memory that really isn't being reclaimed.

2. I've verified (print statements in __del__ methods) that all the
windows and all their controls are getting garbage collected properly,
and the underlying C++ objects seem to be getting deleted also.
There's not a whole lot else involved with a window besides the
controls, certainly not enough to account for 2/3 of the memory usage.

3. In the simplest case (a window with just two controls), it takes
44K to show the window, and closing it reclaims nothing at all. Every
time.

4. Most importantly, the numbers change depending on the version of
Python. In 2.1.0, more memory was expended than described in #2, but
about the same amount was reclaimed in large windows. For the small
window, 2.1.0 showed the behavior in #3 above, while in 2.1.3, the
small window takes 36K to show. Closing it still doesn't release any
memory, *but* the second time the window is shown it will take *zero*
memory, which is what I'd hope for with GC. For larger windows there's
still a big problem, as #1 (figures for 2.1.3) indicates.

The interpreter would normally be the last thing I'd suspect, but
since the behavior changes significantly from version to version of
Python, I'm beginning to wonder if that's the culprit. Can anybody
give suggestions? 2.2.1 has the same results as 2.1.3. Is there any
way to determine whether the leak is in the interpreter's GC or my
Python code or a 3rd-party C module? Any tools available to analyze
the contents of memory?

Thanks,

Bryn



More information about the Python-list mailing list