Tracking down a memory leak
Alex Martelli
aleax at aleax.it
Sun Jan 20 03:04:37 EST 2002
Kip Macy wrote:
> I have a long running python program that typically uses 6-7MB. It can
> happily run for days without any problems, but periodically it will
> balloon and use up all available memory and swap. I'm aware that the
> presence of circular reference can defeat garbage collection. Are there
Only if the instances involved in a reference loop have __del__ methods.
In this case, the garbage collector does still collect them, and puts them
in list gc.garbage, but cannot determine a safe order in which to run the
__del__ methods and thus cannot finalize the objects.
> any recommended utilities or methods for determining what data structures
> are using up all available memory?
import gc and look at gc.garbage. You may solve the problem, not just
by removing the circular references, but also by removing __del__ methods
and by using weak references, see module weakref.
Alex
More information about the Python-list
mailing list