[vtkusers] Python garbage collection of vtkTkRenderWindowInteractor

Richard Layman mdl_126 at hotmail.com
Tue Sep 6 16:20:20 EDT 2005


Hi Pythoneers,

It seems Python has problem releasing memory from the Tk widget 
vtkTkRenderWindowInteractor.  Try the following test code:

import gc, weakref
import Tkinter
#from vtk.tk.vtkTkRenderWidget import vtkTkRenderWidget
from vtk.tk.vtkTkRenderWindowInteractor import vtkTkRenderWindowInteractor

root = Tkinter.Tk()
wids = []
rw = vtk.vtkRenderWindow()
for i in range(10):
#    w = vtkTkRenderWidget(root)
    w = vtkTkRenderWindowInteractor(root)
    w.DebugOn()
    wids.append(weakref.ref(w))
    w.destroy()
    del w
    print 'collect:', gc.collect()
    print 'wids:', wids

The list of weakrefs shows that the widgets, destroyed and deleted, did not 
go away. This is so even though gc.collect is called explicitly. The widgets 
are only freed on exit.

If vtkTkRenderWindowInteractor is replaced vtkTkRenderWidget the widgets go 
away after destruction and deletion, even if gc.collect is not called.

The major difference between the two types of objects as I see is the window 
interactor in the first case. No matter what is going on,  it's just 
troubling to see that python objects cannot be garbage collected.

Opinions?

_________________________________________________________________
On the road to retirement? Check out MSN Life Events for advice on how to 
get there! http://lifeevents.msn.com/category.aspx?cid=Retirement




More information about the vtkusers mailing list