[vtkusers] VTK not releasing memory, including minimal example.
David Gobbi
david.gobbi at gmail.com
Sun Sep 23 11:46:58 EDT 2012
Hi PJ,
The only obvious error that I found in your code was the call to UnRegister():
interactor.UnRegister(actor)
The above is exactly the same as calling interactor->Delete(), and I
don't think that was what you were intending to do. Really, you should
never call UnRegister(). In C++, you should call Delete(), and in
Python, you should always let Python do the GC for you (though
making sure that objects are disconnected can help).
>From looking at your code, I can't say what might be causing the
leaks, but I recommend that you try valgrind with the options
"valgrind --leak-check=full". You can also build VTK with leak
checking enabled, by setting VTK_DEBUG_LEAKS=ON in cmake.
- David
On Sun, Sep 23, 2012 at 7:57 AM, P.J.Schaafsma
<jetze.schaafsma at gmail.com> wrote:
> The code below illustrates a problem where VTK fails to release memory. The
> amount of memory the program uses at the very end, when all actors have been
> removed and the interactor starts, grows approximately linearly with the
> number of iterations.
>
> It comes down to this. If I comment 'key line #1' then the eventual memory
> consumption is in the 10s of Mbs, irrespective of the number of iterations.
> Otherwise, it grows into the hundreds quickly. So at the application code
> leve,l the Render call causes the issue (hence the mapper.Update() call to
> force the pipeline to execute). The volume.vti dataset is about 8Mb on disk.
>
> The problem persists in many configurations. I've tested with:
> VTK 5.6.1 / VTK 5.10.0
> Win7-64 / Kubuntu 12.04-64
> Python 2.7 / C++
> RelWithDeb / Debug VTK builds.
> Pipelined / non-pipelined VTK (using Update/GetOutput/SetInput vs
> GetOutputPort/SetInputConnection)
>
> I've been working on it for quite some time now, trying many different
> solutions I found in various forum post, but of course there's a chance I've
> missed the correct one. Using the DataReleaseFlag in various ways either
> made no difference, or produced incorrect results (not showing anything in
> de render window).
>
> My questions:
> - Is it an issue, or is this somehow by design?
> - Am I missing crucial method calls that would cause this issue?
> - Can anyone confirm the issue?
> - What else can I try?
>
> The Python code
>
> import vtk
>
> renderer = vtk.vtkRenderer()
>
> render_window = vtk.vtkRenderWindow()
> render_window.AddRenderer(renderer)
>
> interactor = vtk.vtkRenderWindowInteractor()
> interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
> interactor.SetRenderWindow(render_window)
> interactor.Initialize()
>
> actors = []
> for i in range(1):
> reader = vtk.vtkXMLImageDataReader()
> #reader.SetFileName('e:\\data\\volume\\volume.vti')
> reader.SetFileName('/media/Data/data/volume/volume.vti')
>
> contour = vtk.vtkContourFilter()
> contour.SetValue(0, 800)
> contour.SetInputConnection(reader.GetOutputPort())
>
> mapper = vtk.vtkPolyDataMapper()
> mapper.SetInputConnection(contour.GetOutputPort())
> mapper.Update()
>
> actor = vtk.vtkActor()
> actor.SetMapper(mapper)
>
> renderer.AddActor(actor)
>
> actors.append(actor)
>
> # key line #1
> render_window.Render()
>
> for actor in actors:
> renderer.RemoveActor(actor)
> interactor.UnRegister(actor)
>
> render_window.Render()
>
> actor.SetMapper(None)
> mapper.SetInputConnection(None)
> contour.SetInputConnection(None)
>
> reader = None
> contour = None
> mapper = None
> actor = None
>
> # key line #2
> interactor.Start()
More information about the vtkusers
mailing list