RePost: Object deletion problem
Nick Belshaw
nickb at earth.ox.ac.uk
Thu Jun 1 07:03:44 EDT 2000
If someone could spare a moment to explain this little observation -
I do not know whether it is significant/expected/unexpected....
I am trying to track down a memory leak and noticed the following in a
piece of test code whilst trying to reproduce some effects.
On a Linux RedHat6.1 Box if I run the code and hit the offered build
button - I simply populate the screen with a number of windows. If I
then hit the destroy button, the windows are removed and the __del__
method of each child is called ok, but if I look at memory usage using
'Top' I see that no memory is released?
However - if I increase the dummy-data count from 30000 to 40000 or
above, the memory IS released.
Is this ok or might it be giving me a problem?
Thanks for any help
Nick/Oxford
---------code-------------(probably mangled)
#!/usr/bin/python
import sys,Tkinter
class Child(Tkinter.Frame):
def __init__(self, window):
self.w = window
Tkinter.Frame.__init__(self,self.w)
self.data = [1.23456789]*30000 #<<<<----dummy data to eat
memory
self.l = Tkinter.Label(self.w,text='hello')
self.l.pack()
def __del__(self):
print 'see delete request ',self
class Parent:
def depopulate(self):
for each in self.childlist:
each.w.destroy()
self.childlist = [0]*self.count
def populate(self):
for a in range(self.count):
new_window = Tkinter.Toplevel(self.W)
self.childlist[a] = Child(new_window)
def __init__(self, W, n=10):
self.count = n
self.childlist = [0]*self.count
self.W = W
self.b1 =
Tkinter.Button(self.W,text='destroy',command=self.depopulate)
self.b1.pack(side='right')
self.b2 =
Tkinter.Button(self.W,text='build',command=self.populate)
self.b2.pack(side='right')
W = Tkinter.Tk()
test = Parent(W,50)
W.mainloop()
----------------------------------------------------------------
More information about the Python-list
mailing list