Trouble deleting objects ? advice please

Nick Belshaw nickb at earth.ox.ac.uk
Tue May 30 13:09:23 CEST 2000


Hi Pythoneers- if someone could spare a mo'

I  am currently suffering a bit of a memory leak using Python with Tk on
my Linux box and am unsure as to whether I am successfully deleting
objects in my code.

I have  a __del__ method in my basic class which I can see is called
when the 'refcount' reaches 2, so I sort of understand that much.

However the objects in question are  instances of a basic class, each of
which is passed a Child Tk window  which it handles independently, along
with a few parameters and functions.

I notice that I must explicitly call  a destroy() on the child-window to
get the refcount down, else __del__ is not called. Is this correct? I
see I can call destroy() on the child repeatedly without raising an
exception. Is this ok or does it indicate it is still alive even though
it has been removed from my display?

Even though I am destroying the TkChild and seeing the __del__ method
being called I am not reclaiming memory.

Am I doing something inside the  Class Instances which might be making
them stay alive even though they are no longer  visible to the rest of
my code? Is there something I can do inside the __del__ method to ensure
removal?
I tried putting in 'del self' but that didn't help!




I would be grateful if someone could tell me what I should be looking at
to get to the bottom of the problem.


cheers
Nick/Oxford





More information about the Python-list mailing list