Possible to assure no "cyclic"/"uncollectible" memory leaks?

Joe Peterson joe at skyrush.com
Sat Dec 2 00:03:33 EST 2006


I've been doing a lot of searching on the topic of one of Python's more
disturbing issues (at least to me): the fact that if a __del__ finalizer
is defined and a cyclic (circular) reference is made, the garbage
collector cannot clean it up.

First of all, it seems that it's best to avoid using __del__.  So far, I
have never used it in my Python programming.  So I am safe there.  Or am
I?  Also, to my knowledge, I have never created a cyclic reference, but
we do not typically create bugs intentionally either (and there are
certainly times when it is an OK thing to do).

Still, it's not comforting to know that it is possible to create a
situation that would create a memory leak using a language that is
supposed to relieve us of that worry.  I understand the problem, but it
would be nice to know that as a programmer, I could be assured that
Python would always deal with memory management and that memory leaks
were not something I had to think about.

So here's a question: if I write Python software and never use __del__,
can I guarantee that there is no way to create a memory leak?  What
about system libraries - do any of them use __del__, and if so, are they
written in such a way that it is not possible to create a cyclic reference?

					Thanks, Joe



More information about the Python-list mailing list