[vtkusers] Memory leak in VTK-Python module
P.J.Schaafsma
jetze.schaafsma at gmail.com
Tue Jul 5 04:56:00 EDT 2011
(Added for the benefit of other people googling "vtk python memory leaks")
The output data object of a VTK filter is owned by the filter. So if you use
the output of a filter, as obtained through GetOutput(), the VTK filter
INCLUDING ITS INPUTS(!!!), will not be garbage collected. So, if you do
something like
gaussian = vtk.vtkGaussianSmooth()
gaussian.SetInput(data_object)
gaussian.Update()
data_object = gaussian.GetOutput()
there will be 2 data objects in memory, instead of 1, as the original
data_object still exists as the input to the filter. What you need to do is
this:
gaussian = vtk.vtkGaussianSmooth()
gaussian.SetInput(data_object)
gaussian.Update()
data_object.DeepCopy(gaussian.GetOutput())
This will cause the filter and its input to be garbage collected as there
are no extra references to the filter's output object, and therefore to the
filter itself.
--
View this message in context: http://vtk.1045678.n5.nabble.com/Memory-leak-in-VTK-Python-module-tp1234002p4552600.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list