Memory leak issue with complex data structure

Hrvoje Niksic hniksic at xemacs.org
Thu Jul 5 09:50:41 CEST 2007


Alan Franzoni <alan.franzoni_invalid at geemail.invalid> writes:

> I have a serious "leak" issue; even though I clear all those sets
> and I delete all the references I can have to the current namespace,
> memory is not freed.

Maybe the memory is freed (marked as available for further use by
Python), just not released to the operating system.[1]  To test against
that, try to allocate more Python structures and see if they reuse the
freed memory or if they allocate even more memory.  Even better, run
code like this:

while 1:
  ... populate your data structures ...
  clear()

If this causes Python to allocate more and more memory, it means you
have a real leak.  If not, it means that the GC is working fine, but
it's not possible to release the memory to the OS.


[1]
Not giving freed memory back to the system is not (necessarily) a
Python bug; the same thing happens in C and is a consequence of
managed memory being assigned to the process as a contiguous block.



More information about the Python-list mailing list