python memory analysis

Alexander Hoffmann alexander.hoffmann at netgenius.de
Wed Sep 8 11:31:11 CEST 2004


Hello Jeremy,

On Tuesday 07 September 2004 17:12, Jeremy Bowers wrote:
> Alexander Hoffmann wrote:
> > Hello Jeremy,
> > Thanks for your help !
> >
> > Indeed a first invocation of gc.get_objects already gave me an idea about
> > what might go wrong. It seems like the garbage collector does not remove
> > objects a and b if a references b even though no one else references
> > either a or b.
> >
> > I will continue my analysis.
>
> My understanding is that in the case where a->b, and nobody else
> referencing either, a and b are to be collected at the next run.
You're right ! What I didn't see at first is that there indeed was another 
reference from b to a. So I had something like a double linked list:
a.next = b
b.prev = a
This lead to a and b - which were not referenced by any other object but 
themselves - were not collected by gc.

> If you can produce a concise test case, I strongly suggest posting it to
> c.l.p. to get more expert opinions on whether it is a Python bug. I only
> know what I've heard the real experts say, and like I said, every time
> I've had this problem and I go to produce a test case, the problem
> vaporizes on me. Without a concise test case, nobody can help.
I feel a bit ashamed because I tend to extensively use unit tests to assure 
quality of my software (my latest project has approx. 9000 lines of code and 
among them are about 4000 only for unit tests) and finally I was able make 
the zombies disappear from memory by manually implementing a destructor for 
all affected classes. Unfortunately none of my tests covered this issue, I'll 
try to change that !

> Good luck!
Thanks   :-)

btw: while searching my memory leak I figured out another issue which I will 
post in a separate thread. There are thousands of tuples allocated by Python 
which are not freed again. Let's see what people around here know about 
this...

--alex



More information about the Python-list mailing list