Urgent : How to do memory leaks detection in python ?

tsuraan tsuraan at gmail.com
Sat Mar 15 22:56:35 EDT 2008


> Python doesn't have memory leaks.

Yeah, interesting bit of trivia: python is the world's only non-trivial
program that's totally free of bugs.  Pretty exciting!  But seriously,
python 2.4, at least, does have some pretty trivially exposed memory leaks
when working with strings.  A simple example is this:

>>> letters = [chr(c) for c in range(ord('a'), ord('z'))+range(ord('A'),
ord('Z'))]
>>> ary = []
>>> for a in letters:
...  for b in letters:
...   for c in letters:
...    for d in letters:
...     ary.append(a+b+c+d)
...
>>> del(ary)
>>> import gc
>>> gc.collect()
0

The VM's memory usage will never drop from its high point of (on my
computer) ~200MB.  Since you're using GIS data, this could be what you're
running into.  I haven't been able to upgrade my systems to python 2.5, but
from my tests, that version did not have that memory leak.  Nobody seems
interesting in backporting fixes from 2.5 to 2.4, so you're probably on your
own in that case as well, if upgrading to python 2.5 isn't an option or
isn't applicable to your situation.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080315/941d321a/attachment-0001.html>


More information about the Python-list mailing list