VTK not releasing memory, including minimal example.

classic Classic list List threaded Threaded
21 messages Options
12
Reply | Threaded
Open this post in threaded view
|

VTK not releasing memory, including minimal example.

P.J.Schaafsma
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()
Reply | Threaded
Open this post in threaded view
|

Re: VTK not releasing memory, including minimal example.

David Gobbi
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
<[hidden email]> 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()
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: VTK not releasing memory, including minimal example.

P.J.Schaafsma
Here's some even simpler C++ code that has the same problem. I shouldn't have to explicitly Unregister the actors to make them reach reference count 0. That wouldn't make sense.

The extra render window creation at the bottom is used to track how much memory is 'lost' eventually. With the key line with the Render() call commented out, memory use is 14Mb during both the first and second event loops triggered by interactor->Start(). With the key line enabled. Memory use is 115Mb during the first, and 54Mb during the second event loop.

valgrind shows only a few hundred kbytes unfreed at program exit. The many invalid reads are expected, and they show that the objects are actually being deleted. Interspersed with the valgrind output is also the result of the print statements, showing undefined values for object reference counts.


C++ Code

int main()
{
        vtkXMLImageDataReader *reader = vtkXMLImageDataReader::New();
        //reader->SetFileName("e:\\data\\volume\\manix_low.vti");
        reader->SetFileName("/media/Data/data/volume/manix_low.vti");

        vtkContourFilter *contour = vtkContourFilter::New();
        contour->SetInputConnection(reader->GetOutputPort());
        contour->SetValue(0, 800);

        vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
        mapper->SetInputConnection(contour->GetOutputPort());
        mapper->Update();

        vtkActor *actor = vtkActor::New();
        actor->SetMapper(mapper);

        vtkRenderer *renderer = vtkRenderer::New();
        renderer->AddActor(actor);

        vtkRenderWindow *render_window = vtkRenderWindow::New();
        render_window->AddRenderer(renderer);

        vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New();
       
        vtkRenderWindowInteractor *interactor = vtkRenderWindowInteractor::New();
        interactor->SetInteractorStyle(style);
        interactor->SetRenderWindow(render_window);
        interactor->Initialize();
       
        printf("contour: %d\n", contour->GetReferenceCount());
        printf("mapper: %d\n", mapper->GetReferenceCount());
        printf("actor: %d\n", actor->GetReferenceCount());
        printf("renderer: %d\n", renderer->GetReferenceCount());
        printf("render_window: %d\n", render_window->GetReferenceCount());
        printf("interactor: %d\n", interactor->GetReferenceCount());
        printf("style: %d\n", style->GetReferenceCount());
        printf("\n");
         
        ////// Comment this out and save memory
        render_window->Render();
        //////

        printf("contour: %d\n", contour->GetReferenceCount());
        printf("mapper: %d\n", mapper->GetReferenceCount());
        printf("actor: %d\n", actor->GetReferenceCount());
        printf("renderer: %d\n", renderer->GetReferenceCount());
        printf("render_window: %d\n", render_window->GetReferenceCount());
        printf("interactor: %d\n", interactor->GetReferenceCount());
        printf("style: %d\n", style->GetReferenceCount());
        printf("\n");
       
        renderer->RemoveActor(actor);
        render_window->Render();

        printf("contour: %d\n", contour->GetReferenceCount());
        printf("mapper: %d\n", mapper->GetReferenceCount());
        printf("actor: %d\n", actor->GetReferenceCount());
        printf("renderer: %d\n", renderer->GetReferenceCount());
        printf("render_window: %d\n", render_window->GetReferenceCount());
        printf("interactor: %d\n", interactor->GetReferenceCount());
        printf("style: %d\n", style->GetReferenceCount());
        printf("\n");
       
       
        actor->Delete();
        mapper->Delete();
        contour->Delete();
        reader->Delete();

        printf("contour: %d\n", contour->GetReferenceCount());
        printf("mapper: %d\n", mapper->GetReferenceCount());
        printf("actor: %d\n", actor->GetReferenceCount());
        printf("renderer: %d\n", renderer->GetReferenceCount());
        printf("render_window: %d\n", render_window->GetReferenceCount());
        printf("interactor: %d\n", interactor->GetReferenceCount());
        printf("style: %d\n", style->GetReferenceCount());
        printf("\n");
       

        interactor->Start();
       
        render_window->RemoveRenderer(renderer);
        interactor->SetInteractorStyle(0);
       
        style->Delete();
        interactor->Delete();
        renderer->Delete();
        render_window->Delete();
       
        printf("contour: %d\n", contour->GetReferenceCount());
        printf("mapper: %d\n", mapper->GetReferenceCount());
        printf("actor: %d\n", actor->GetReferenceCount());
        printf("renderer: %d\n", renderer->GetReferenceCount());
        printf("render_window: %d\n", render_window->GetReferenceCount());
        printf("interactor: %d\n", interactor->GetReferenceCount());
        printf("style: %d\n", style->GetReferenceCount());
        printf("\n");
       
        render_window = vtkRenderWindow::New();
        interactor = vtkRenderWindowInteractor::New();
        interactor->SetRenderWindow(render_window);
        interactor->Initialize();
        interactor->Start();
       
       
        printf("Done\n");
       
        return 0;

Valgrind output

==9499== Memcheck, a memory error detector
==9499== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==9499== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==9499== Command: ../../../../bin/Cone5
==9499==
contour: 2
mapper: 3
actor: 2
renderer: 2
render_window: 2
interactor: 2
style: 2

==9499== Conditional jump or move depends on uninitialised value(s)
==9499==    at 0xD47E900: ??? (in /usr/lib/nvidia-current/libnvidia-glcore.so.295.40)
==9499==    by 0x7FEFFFEDF: ???
==9499==    by 0x7FEFFF0DF: ???
==9499==    by 0xE272F1F: ???
==9499==    by 0x7FEFFF01F: ???
==9499==    by 0x7FEFFF137: ???
==9499==    by 0x40B4DE7: ???
==9499==    by 0x4070FFF: ??? (in /dev/nvidia0)
==9499==    by 0x17F5E03F: ???
==9499==    by 0x1360E32F: ???
==9499==    by 0xFC4F67F: ???
==9499==    by 0x1FFFFFFFF: ???
==9499==
==9499== Conditional jump or move depends on uninitialised value(s)
==9499==    at 0xD47E909: ??? (in /usr/lib/nvidia-current/libnvidia-glcore.so.295.40)
==9499==    by 0x7FEFFFEDF: ???
==9499==    by 0x7FEFFF0DF: ???
==9499==    by 0xE272F1F: ???
==9499==    by 0x7FEFFF01F: ???
==9499==    by 0x7FEFFF137: ???
==9499==    by 0x40B4DE7: ???
==9499==    by 0x4070FFF: ??? (in /dev/nvidia0)
==9499==    by 0x17F5E03F: ???
==9499==    by 0x1360E32F: ???
==9499==    by 0xFC4F67F: ???
==9499==    by 0x1FFFFFFFF: ???
==9499==
==9499== Use of uninitialised value of size 8
==9499==    at 0xD47E916: ??? (in /usr/lib/nvidia-current/libnvidia-glcore.so.295.40)
==9499==    by 0x7FEFFFEDF: ???
==9499==    by 0x7FEFFF0DF: ???
==9499==    by 0xE272F1F: ???
==9499==    by 0x7FEFFF01F: ???
==9499==    by 0x7FEFFF137: ???
==9499==    by 0x40B4DE7: ???
==9499==    by 0x4070FFF: ??? (in /dev/nvidia0)
==9499==    by 0x17F5E03F: ???
==9499==    by 0x1360E32F: ???
==9499==    by 0xFC4F67F: ???
==9499==    by 0x1FFFFFFFF: ???
==9499==
contour: 2
mapper: 3
actor: 2
renderer: 2
render_window: 2
interactor: 2
style: 2

contour: 2
mapper: 3
actor: 1
renderer: 2
render_window: 2
interactor: 2
style: 2

==9499== Invalid read of size 4
==9499==    at 0x401798: vtkObjectBase::GetReferenceCount() (vtkObjectBase.h:143)
==9499==    by 0x401485: main (Cone5.cxx:109)
==9499==  Address 0xfbfec58 is 8 bytes inside a block of size 200 free'd
==9499==    at 0x4C2A4BC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9499==    by 0x637B1DF: vtkContourFilter::~vtkContourFilter() (vtkContourFilter.cxx:95)
==9499==    by 0x781C8F0: vtkObjectBase::UnRegisterInternal(vtkObjectBase*, int) (vtkObjectBase.cxx:286)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int) (vtkObject.cxx:885)
==9499==    by 0x77A11F8: vtkGarbageCollectorToObjectBaseFriendship::UnRegister(vtkObjectBase*, vtkObjectBase*) (vtkGarbageCollector.cxx:141)
==9499==    by 0x779FB69: vtkGarbageCollectorImpl::CollectComponent(vtkGarbageCollectorImpl::ComponentType*) (vtkGarbageCollector.cxx:702)
==9499==    by 0x779EDE0: vtkGarbageCollectorImpl::CollectInternal(vtkObjectBase*) (vtkGarbageCollector.cxx:473)
==9499==    by 0x77A0A14: vtkGarbageCollector::Collect(vtkObjectBase*) (vtkGarbageCollector.cxx:904)
==9499==    by 0x781C904: vtkObjectBase::UnRegisterInternal(vtkObjectBase*, int) (vtkObjectBase.cxx:294)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int) (vtkObject.cxx:885)
==9499==    by 0x6F8B8F3: vtkAlgorithm::UnRegister(vtkObjectBase*) (vtkAlgorithm.cxx:917)
==9499==    by 0x781C29B: vtkObjectBase::Delete() (vtkObjectBase.cxx:134)
==9499==
contour: 0
==9499== Invalid read of size 4
==9499==    at 0x401798: vtkObjectBase::GetReferenceCount() (vtkObjectBase.h:143)
==9499==    by 0x4014A2: main (Cone5.cxx:110)
==9499==  Address 0xfc15e18 is 8 bytes inside a block of size 664 free'd
==9499==    at 0x4C2A4BC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9499==    by 0x5153D63: vtkPainterPolyDataMapper::~vtkPainterPolyDataMapper() (vtkPainterPolyDataMapper.cxx:96)
==9499==    by 0x781C8F0: vtkObjectBase::UnRegisterInternal(vtkObjectBase*, int) (vtkObjectBase.cxx:286)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int) (vtkObject.cxx:885)
==9499==    by 0x77A11F8: vtkGarbageCollectorToObjectBaseFriendship::UnRegister(vtkObjectBase*, vtkObjectBase*) (vtkGarbageCollector.cxx:141)
==9499==    by 0x779FB69: vtkGarbageCollectorImpl::CollectComponent(vtkGarbageCollectorImpl::ComponentType*) (vtkGarbageCollector.cxx:702)
==9499==    by 0x779EDE0: vtkGarbageCollectorImpl::CollectInternal(vtkObjectBase*) (vtkGarbageCollector.cxx:473)
==9499==    by 0x77A0A14: vtkGarbageCollector::Collect(vtkObjectBase*) (vtkGarbageCollector.cxx:904)
==9499==    by 0x781C904: vtkObjectBase::UnRegisterInternal(vtkObjectBase*, int) (vtkObjectBase.cxx:294)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int) (vtkObject.cxx:885)
==9499==    by 0x6F8B8F3: vtkAlgorithm::UnRegister(vtkObjectBase*) (vtkAlgorithm.cxx:917)
==9499==    by 0x781C29B: vtkObjectBase::Delete() (vtkObjectBase.cxx:134)
==9499==
mapper: 0
==9499== Invalid read of size 4
==9499==    at 0x401798: vtkObjectBase::GetReferenceCount() (vtkObjectBase.h:143)
==9499==    by 0x4014BF: main (Cone5.cxx:111)
==9499==  Address 0x127d71d8 is 8 bytes inside a block of size 440 free'd
==9499==    at 0x4C2A4BC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9499==    by 0x5265837: vtkOpenGLActor::~vtkOpenGLActor() (vtkOpenGLActor.h:42)
==9499==    by 0x781C8F0: vtkObjectBase::UnRegisterInternal(vtkObjectBase*, int) (vtkObjectBase.cxx:286)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int) (vtkObject.cxx:885)
==9499==    by 0x781C515: vtkObjectBase::UnRegister(vtkObjectBase*) (vtkObjectBase.cxx:189)
==9499==    by 0x781C29B: vtkObjectBase::Delete() (vtkObjectBase.cxx:134)
==9499==    by 0x401434: main (Cone5.cxx:104)
==9499==
actor: 0
renderer: 2
render_window: 2
interactor: 2
style: 2

==9499== Invalid read of size 4
==9499==    at 0x401798: vtkObjectBase::GetReferenceCount() (vtkObjectBase.h:143)
==9499==    by 0x401600: main (Cone5.cxx:129)
==9499==  Address 0xfbfec58 is 8 bytes inside a block of size 200 free'd
==9499==    at 0x4C2A4BC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9499==    by 0x637B1DF: vtkContourFilter::~vtkContourFilter() (vtkContourFilter.cxx:95)
==9499==    by 0x781C8F0: vtkObjectBase::UnRegisterInternal(vtkObjectBase*, int) (vtkObjectBase.cxx:286)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int) (vtkObject.cxx:885)
==9499==    by 0x77A11F8: vtkGarbageCollectorToObjectBaseFriendship::UnRegister(vtkObjectBase*, vtkObjectBase*) (vtkGarbageCollector.cxx:141)
==9499==    by 0x779FB69: vtkGarbageCollectorImpl::CollectComponent(vtkGarbageCollectorImpl::ComponentType*) (vtkGarbageCollector.cxx:702)
==9499==    by 0x779EDE0: vtkGarbageCollectorImpl::CollectInternal(vtkObjectBase*) (vtkGarbageCollector.cxx:473)
==9499==    by 0x77A0A14: vtkGarbageCollector::Collect(vtkObjectBase*) (vtkGarbageCollector.cxx:904)
==9499==    by 0x781C904: vtkObjectBase::UnRegisterInternal(vtkObjectBase*, int) (vtkObjectBase.cxx:294)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int) (vtkObject.cxx:885)
==9499==    by 0x6F8B8F3: vtkAlgorithm::UnRegister(vtkObjectBase*) (vtkAlgorithm.cxx:917)
==9499==    by 0x781C29B: vtkObjectBase::Delete() (vtkObjectBase.cxx:134)
==9499==
contour: 0
==9499== Invalid read of size 4
==9499==    at 0x401798: vtkObjectBase::GetReferenceCount() (vtkObjectBase.h:143)
==9499==    by 0x40161D: main (Cone5.cxx:130)
==9499==  Address 0xfc15e18 is 8 bytes inside a block of size 664 free'd
==9499==    at 0x4C2A4BC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9499==    by 0x5153D63: vtkPainterPolyDataMapper::~vtkPainterPolyDataMapper() (vtkPainterPolyDataMapper.cxx:96)
==9499==    by 0x781C8F0: vtkObjectBase::UnRegisterInternal(vtkObjectBase*, int) (vtkObjectBase.cxx:286)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int) (vtkObject.cxx:885)
==9499==    by 0x77A11F8: vtkGarbageCollectorToObjectBaseFriendship::UnRegister(vtkObjectBase*, vtkObjectBase*) (vtkGarbageCollector.cxx:141)
==9499==    by 0x779FB69: vtkGarbageCollectorImpl::CollectComponent(vtkGarbageCollectorImpl::ComponentType*) (vtkGarbageCollector.cxx:702)
==9499==    by 0x779EDE0: vtkGarbageCollectorImpl::CollectInternal(vtkObjectBase*) (vtkGarbageCollector.cxx:473)
==9499==    by 0x77A0A14: vtkGarbageCollector::Collect(vtkObjectBase*) (vtkGarbageCollector.cxx:904)
==9499==    by 0x781C904: vtkObjectBase::UnRegisterInternal(vtkObjectBase*, int) (vtkObjectBase.cxx:294)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int) (vtkObject.cxx:885)
==9499==    by 0x6F8B8F3: vtkAlgorithm::UnRegister(vtkObjectBase*) (vtkAlgorithm.cxx:917)
==9499==    by 0x781C29B: vtkObjectBase::Delete() (vtkObjectBase.cxx:134)
==9499==
mapper: 0
==9499== Invalid read of size 4
==9499==    at 0x401798: vtkObjectBase::GetReferenceCount() (vtkObjectBase.h:143)
==9499==    by 0x40163A: main (Cone5.cxx:131)
==9499==  Address 0x127d71d8 is 8 bytes inside a block of size 440 free'd
==9499==    at 0x4C2A4BC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9499==    by 0x5265837: vtkOpenGLActor::~vtkOpenGLActor() (vtkOpenGLActor.h:42)
==9499==    by 0x781C8F0: vtkObjectBase::UnRegisterInternal(vtkObjectBase*, int) (vtkObjectBase.cxx:286)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int) (vtkObject.cxx:885)
==9499==    by 0x781C515: vtkObjectBase::UnRegister(vtkObjectBase*) (vtkObjectBase.cxx:189)
==9499==    by 0x781C29B: vtkObjectBase::Delete() (vtkObjectBase.cxx:134)
==9499==    by 0x401434: main (Cone5.cxx:104)
==9499==
actor: 0
==9499== Invalid read of size 4
==9499==    at 0x401798: vtkObjectBase::GetReferenceCount() (vtkObjectBase.h:143)
==9499==    by 0x401657: main (Cone5.cxx:132)
==9499==  Address 0x1284a2f8 is 8 bytes inside a block of size 808 free'd
==9499==    at 0x4C2A4BC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9499==    by 0x52A411D: vtkOpenGLRenderer::~vtkOpenGLRenderer() (vtkOpenGLRenderer.cxx:1278)
==9499==    by 0x781C8F0: vtkObjectBase::UnRegisterInternal(vtkObjectBase*, int) (vtkObjectBase.cxx:286)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int) (vtkObject.cxx:885)
==9499==    by 0x781C515: vtkObjectBase::UnRegister(vtkObjectBase*) (vtkObjectBase.cxx:189)
==9499==    by 0x781C29B: vtkObjectBase::Delete() (vtkObjectBase.cxx:134)
==9499==    by 0x4015DD: main (Cone5.cxx:126)
==9499==
renderer: 0
==9499== Invalid read of size 4
==9499==    at 0x401798: vtkObjectBase::GetReferenceCount() (vtkObjectBase.h:143)
==9499==    by 0x401674: main (Cone5.cxx:133)
==9499==  Address 0x1284a8b8 is 8 bytes inside a block of size 632 free'd
==9499==    at 0x4C2A4BC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9499==    by 0x52F5C59: vtkXOpenGLRenderWindow::~vtkXOpenGLRenderWindow() (vtkXOpenGLRenderWindow.cxx:455)
==9499==    by 0x781C8F0: vtkObjectBase::UnRegisterInternal(vtkObjectBase*, int) (vtkObjectBase.cxx:286)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int) (vtkObject.cxx:885)
==9499==    by 0x781C515: vtkObjectBase::UnRegister(vtkObjectBase*) (vtkObjectBase.cxx:189)
==9499==    by 0x51B6D56: vtkRenderWindow::UnRegister(vtkObjectBase*) (vtkRenderWindow.cxx:1309)
==9499==    by 0x51BF26A: vtkRenderWindowInteractor::SetRenderWindow(vtkRenderWindow*) (vtkRenderWindowInteractor.cxx:194)
==9499==    by 0x51B6D25: vtkRenderWindow::UnRegister(vtkObjectBase*) (vtkRenderWindow.cxx:1303)
==9499==    by 0x781C29B: vtkObjectBase::Delete() (vtkObjectBase.cxx:134)
==9499==    by 0x4015F4: main (Cone5.cxx:127)
==9499==
render_window: 0
==9499== Invalid read of size 4
==9499==    at 0x401798: vtkObjectBase::GetReferenceCount() (vtkObjectBase.h:143)
==9499==    by 0x401691: main (Cone5.cxx:134)
==9499==  Address 0x127e70e8 is 8 bytes inside a block of size 312 free'd
==9499==    at 0x4C2A4BC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9499==    by 0x525253F: vtkXRenderWindowInteractor::~vtkXRenderWindowInteractor() (vtkXRenderWindowInteractor.cxx:147)
==9499==    by 0x781C8F0: vtkObjectBase::UnRegisterInternal(vtkObjectBase*, int) (vtkObjectBase.cxx:286)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int) (vtkObject.cxx:885)
==9499==    by 0x781C515: vtkObjectBase::UnRegister(vtkObjectBase*) (vtkObjectBase.cxx:189)
==9499==    by 0x51BF203: vtkRenderWindowInteractor::UnRegister(vtkObjectBase*) (vtkRenderWindowInteractor.cxx:181)
==9499==    by 0x51B6D41: vtkRenderWindow::UnRegister(vtkObjectBase*) (vtkRenderWindow.cxx:1304)
==9499==    by 0x781C29B: vtkObjectBase::Delete() (vtkObjectBase.cxx:134)
==9499==    by 0x4015F4: main (Cone5.cxx:127)
==9499==
interactor: 0
==9499== Invalid read of size 4
==9499==    at 0x401798: vtkObjectBase::GetReferenceCount() (vtkObjectBase.h:143)
==9499==    by 0x4016AE: main (Cone5.cxx:135)
==9499==  Address 0x1284ad18 is 8 bytes inside a block of size 280 free'd
==9499==    at 0x4C2A4BC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9499==    by 0x50CBE9F: vtkInteractorStyleTrackballCamera::~vtkInteractorStyleTrackballCamera() (vtkInteractorStyleTrackballCamera.cxx:36)
==9499==    by 0x781C8F0: vtkObjectBase::UnRegisterInternal(vtkObjectBase*, int) (vtkObjectBase.cxx:286)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int) (vtkObject.cxx:885)
==9499==    by 0x781C515: vtkObjectBase::UnRegister(vtkObjectBase*) (vtkObjectBase.cxx:189)
==9499==    by 0x781C29B: vtkObjectBase::Delete() (vtkObjectBase.cxx:134)
==9499==    by 0x4015AF: main (Cone5.cxx:124)
==9499==
style: 0

Done
==9499==
==9499== FILE DESCRIPTORS: 5 open at exit.
==9499== Open AF_UNIX socket 3: <unknown>
==9499==    at 0x805D757: socket (syscall-template.S:82)
==9499==    by 0xEAB80BA: ??? (in /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0)
==9499==    by 0xEAB8543: xcb_connect_to_display_with_auth_info (in /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0)
==9499==    by 0x9427EF1: _XConnectXCB (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==9499==    by 0x9418A40: XOpenDisplay (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==9499==    by 0x91A354E: XtOpenDisplay (in /usr/lib/x86_64-linux-gnu/libXt.so.6.0.0)
==9499==    by 0x5252EA3: vtkXRenderWindowInteractor::Initialize() (vtkXRenderWindowInteractor.cxx:366)
==9499==    by 0x401707: main (Cone5.cxx:141)
==9499==
==9499== Open file descriptor 9: /proc/2720/auxv
==9499==    <inherited from parent>
==9499==
==9499== Open file descriptor 2: /dev/pts/1
==9499==    <inherited from parent>
==9499==
==9499== Open file descriptor 1: /dev/pts/1
==9499==    <inherited from parent>
==9499==
==9499== Open file descriptor 0: /dev/pts/1
==9499==    <inherited from parent>
==9499==
==9499==
==9499== HEAP SUMMARY:
==9499==     in use at exit: 508,751 bytes in 2,432 blocks
==9499==   total heap usage: 32,927 allocs, 30,495 frees, 915,497,381 bytes allocated
==9499==
==9499== LEAK SUMMARY:
==9499==    definitely lost: 262,268 bytes in 3 blocks
==9499==    indirectly lost: 176 bytes in 4 blocks
==9499==      possibly lost: 180 bytes in 5 blocks
==9499==    still reachable: 246,127 bytes in 2,420 blocks
==9499==         suppressed: 0 bytes in 0 blocks
==9499== Rerun with --leak-check=full to see details of leaked memory
==9499==
==9499== For counts of detected and suppressed errors, rerun with: -v
==9499== Use --track-origins=yes to see where uninitialised values come from
==9499== ERROR SUMMARY: 6153 errors from 13 contexts (suppressed: 2 from 2)
Reply | Threaded
Open this post in threaded view
|

Re: VTK not releasing memory, including minimal example.

Bill Lorensen
You must delete the interactor before exit.

In C++ I always use vtkSmartPointer's and do not use Delete()'s.

On Sun, Sep 23, 2012 at 1:13 PM, P.J.Schaafsma <[hidden email]> wrote:
Here's some even simpler C++ code that has the same problem. I shouldn't have
to explicitly Unregister the actors to make them reach reference count 0.
That wouldn't make sense.

The extra render window creation at the bottom is used to track how much
memory is 'lost' eventually. With the key line with the Render() call
commented out, memory use is 14Mb during both the first and second event
loops triggered by interactor->Start(). With the key line enabled. Memory
use is 115Mb during the first, and 54Mb during the second event loop.

valgrind shows only a few hundred kbytes unfreed at program exit. The many
invalid reads are expected, and they show that the objects are actually
being deleted. Interspersed with the valgrind output is also the result of
the print statements, showing undefined values for object reference counts.


C++ Code

int main()
{
        vtkXMLImageDataReader *reader = vtkXMLImageDataReader::New();
        //reader->SetFileName("e:\\data\\volume\\manix_low.vti");
        reader->SetFileName("/media/Data/data/volume/manix_low.vti");

        vtkContourFilter *contour = vtkContourFilter::New();
        contour->SetInputConnection(reader->GetOutputPort());
        contour->SetValue(0, 800);

        vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
        mapper->SetInputConnection(contour->GetOutputPort());
        mapper->Update();

        vtkActor *actor = vtkActor::New();
        actor->SetMapper(mapper);

        vtkRenderer *renderer = vtkRenderer::New();
        renderer->AddActor(actor);

        vtkRenderWindow *render_window = vtkRenderWindow::New();
        render_window->AddRenderer(renderer);

        vtkInteractorStyleTrackballCamera *style =
vtkInteractorStyleTrackballCamera::New();

        vtkRenderWindowInteractor *interactor = vtkRenderWindowInteractor::New();
        interactor->SetInteractorStyle(style);
        interactor->SetRenderWindow(render_window);
        interactor->Initialize();

        printf("contour: %d\n", contour->GetReferenceCount());
        printf("mapper: %d\n", mapper->GetReferenceCount());
        printf("actor: %d\n", actor->GetReferenceCount());
        printf("renderer: %d\n", renderer->GetReferenceCount());
        printf("render_window: %d\n", render_window->GetReferenceCount());
        printf("interactor: %d\n", interactor->GetReferenceCount());
        printf("style: %d\n", style->GetReferenceCount());
        printf("\n");

        ////// Comment this out and save memory
        render_window->Render();
        //////

        printf("contour: %d\n", contour->GetReferenceCount());
        printf("mapper: %d\n", mapper->GetReferenceCount());
        printf("actor: %d\n", actor->GetReferenceCount());
        printf("renderer: %d\n", renderer->GetReferenceCount());
        printf("render_window: %d\n", render_window->GetReferenceCount());
        printf("interactor: %d\n", interactor->GetReferenceCount());
        printf("style: %d\n", style->GetReferenceCount());
        printf("\n");

        renderer->RemoveActor(actor);
        render_window->Render();

        printf("contour: %d\n", contour->GetReferenceCount());
        printf("mapper: %d\n", mapper->GetReferenceCount());
        printf("actor: %d\n", actor->GetReferenceCount());
        printf("renderer: %d\n", renderer->GetReferenceCount());
        printf("render_window: %d\n", render_window->GetReferenceCount());
        printf("interactor: %d\n", interactor->GetReferenceCount());
        printf("style: %d\n", style->GetReferenceCount());
        printf("\n");


        actor->Delete();
        mapper->Delete();
        contour->Delete();
        reader->Delete();

        printf("contour: %d\n", contour->GetReferenceCount());
        printf("mapper: %d\n", mapper->GetReferenceCount());
        printf("actor: %d\n", actor->GetReferenceCount());
        printf("renderer: %d\n", renderer->GetReferenceCount());
        printf("render_window: %d\n", render_window->GetReferenceCount());
        printf("interactor: %d\n", interactor->GetReferenceCount());
        printf("style: %d\n", style->GetReferenceCount());
        printf("\n");


        interactor->Start();

        render_window->RemoveRenderer(renderer);
        interactor->SetInteractorStyle(0);

        style->Delete();
        interactor->Delete();
        renderer->Delete();
        render_window->Delete();

        printf("contour: %d\n", contour->GetReferenceCount());
        printf("mapper: %d\n", mapper->GetReferenceCount());
        printf("actor: %d\n", actor->GetReferenceCount());
        printf("renderer: %d\n", renderer->GetReferenceCount());
        printf("render_window: %d\n", render_window->GetReferenceCount());
        printf("interactor: %d\n", interactor->GetReferenceCount());
        printf("style: %d\n", style->GetReferenceCount());
        printf("\n");

        render_window = vtkRenderWindow::New();
        interactor = vtkRenderWindowInteractor::New();
        interactor->SetRenderWindow(render_window);
        interactor->Initialize();
        interactor->Start();


        printf("Done\n");

        return 0;

Valgrind output

==9499== Memcheck, a memory error detector
==9499== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==9499== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==9499== Command: ../../../../bin/Cone5
==9499==
contour: 2
mapper: 3
actor: 2
renderer: 2
render_window: 2
interactor: 2
style: 2

==9499== Conditional jump or move depends on uninitialised value(s)
==9499==    at 0xD47E900: ??? (in
/usr/lib/nvidia-current/libnvidia-glcore.so.295.40)
==9499==    by 0x7FEFFFEDF: ???
==9499==    by 0x7FEFFF0DF: ???
==9499==    by 0xE272F1F: ???
==9499==    by 0x7FEFFF01F: ???
==9499==    by 0x7FEFFF137: ???
==9499==    by 0x40B4DE7: ???
==9499==    by 0x4070FFF: ??? (in /dev/nvidia0)
==9499==    by 0x17F5E03F: ???
==9499==    by 0x1360E32F: ???
==9499==    by 0xFC4F67F: ???
==9499==    by 0x1FFFFFFFF: ???
==9499==
==9499== Conditional jump or move depends on uninitialised value(s)
==9499==    at 0xD47E909: ??? (in
/usr/lib/nvidia-current/libnvidia-glcore.so.295.40)
==9499==    by 0x7FEFFFEDF: ???
==9499==    by 0x7FEFFF0DF: ???
==9499==    by 0xE272F1F: ???
==9499==    by 0x7FEFFF01F: ???
==9499==    by 0x7FEFFF137: ???
==9499==    by 0x40B4DE7: ???
==9499==    by 0x4070FFF: ??? (in /dev/nvidia0)
==9499==    by 0x17F5E03F: ???
==9499==    by 0x1360E32F: ???
==9499==    by 0xFC4F67F: ???
==9499==    by 0x1FFFFFFFF: ???
==9499==
==9499== Use of uninitialised value of size 8
==9499==    at 0xD47E916: ??? (in
/usr/lib/nvidia-current/libnvidia-glcore.so.295.40)
==9499==    by 0x7FEFFFEDF: ???
==9499==    by 0x7FEFFF0DF: ???
==9499==    by 0xE272F1F: ???
==9499==    by 0x7FEFFF01F: ???
==9499==    by 0x7FEFFF137: ???
==9499==    by 0x40B4DE7: ???
==9499==    by 0x4070FFF: ??? (in /dev/nvidia0)
==9499==    by 0x17F5E03F: ???
==9499==    by 0x1360E32F: ???
==9499==    by 0xFC4F67F: ???
==9499==    by 0x1FFFFFFFF: ???
==9499==
contour: 2
mapper: 3
actor: 2
renderer: 2
render_window: 2
interactor: 2
style: 2

contour: 2
mapper: 3
actor: 1
renderer: 2
render_window: 2
interactor: 2
style: 2

==9499== Invalid read of size 4
==9499==    at 0x401798: vtkObjectBase::GetReferenceCount()
(vtkObjectBase.h:143)
==9499==    by 0x401485: main (Cone5.cxx:109)
==9499==  Address 0xfbfec58 is 8 bytes inside a block of size 200 free'd
==9499==    at 0x4C2A4BC: operator delete(void*) (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9499==    by 0x637B1DF: vtkContourFilter::~vtkContourFilter()
(vtkContourFilter.cxx:95)
==9499==    by 0x781C8F0: vtkObjectBase::UnRegisterInternal(vtkObjectBase*,
int) (vtkObjectBase.cxx:286)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int)
(vtkObject.cxx:885)
==9499==    by 0x77A11F8:
vtkGarbageCollectorToObjectBaseFriendship::UnRegister(vtkObjectBase*,
vtkObjectBase*) (vtkGarbageCollector.cxx:141)
==9499==    by 0x779FB69:
vtkGarbageCollectorImpl::CollectComponent(vtkGarbageCollectorImpl::ComponentType*)
(vtkGarbageCollector.cxx:702)
==9499==    by 0x779EDE0:
vtkGarbageCollectorImpl::CollectInternal(vtkObjectBase*)
(vtkGarbageCollector.cxx:473)
==9499==    by 0x77A0A14: vtkGarbageCollector::Collect(vtkObjectBase*)
(vtkGarbageCollector.cxx:904)
==9499==    by 0x781C904: vtkObjectBase::UnRegisterInternal(vtkObjectBase*,
int) (vtkObjectBase.cxx:294)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int)
(vtkObject.cxx:885)
==9499==    by 0x6F8B8F3: vtkAlgorithm::UnRegister(vtkObjectBase*)
(vtkAlgorithm.cxx:917)
==9499==    by 0x781C29B: vtkObjectBase::Delete() (vtkObjectBase.cxx:134)
==9499==
contour: 0
==9499== Invalid read of size 4
==9499==    at 0x401798: vtkObjectBase::GetReferenceCount()
(vtkObjectBase.h:143)
==9499==    by 0x4014A2: main (Cone5.cxx:110)
==9499==  Address 0xfc15e18 is 8 bytes inside a block of size 664 free'd
==9499==    at 0x4C2A4BC: operator delete(void*) (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9499==    by 0x5153D63:
vtkPainterPolyDataMapper::~vtkPainterPolyDataMapper()
(vtkPainterPolyDataMapper.cxx:96)
==9499==    by 0x781C8F0: vtkObjectBase::UnRegisterInternal(vtkObjectBase*,
int) (vtkObjectBase.cxx:286)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int)
(vtkObject.cxx:885)
==9499==    by 0x77A11F8:
vtkGarbageCollectorToObjectBaseFriendship::UnRegister(vtkObjectBase*,
vtkObjectBase*) (vtkGarbageCollector.cxx:141)
==9499==    by 0x779FB69:
vtkGarbageCollectorImpl::CollectComponent(vtkGarbageCollectorImpl::ComponentType*)
(vtkGarbageCollector.cxx:702)
==9499==    by 0x779EDE0:
vtkGarbageCollectorImpl::CollectInternal(vtkObjectBase*)
(vtkGarbageCollector.cxx:473)
==9499==    by 0x77A0A14: vtkGarbageCollector::Collect(vtkObjectBase*)
(vtkGarbageCollector.cxx:904)
==9499==    by 0x781C904: vtkObjectBase::UnRegisterInternal(vtkObjectBase*,
int) (vtkObjectBase.cxx:294)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int)
(vtkObject.cxx:885)
==9499==    by 0x6F8B8F3: vtkAlgorithm::UnRegister(vtkObjectBase*)
(vtkAlgorithm.cxx:917)
==9499==    by 0x781C29B: vtkObjectBase::Delete() (vtkObjectBase.cxx:134)
==9499==
mapper: 0
==9499== Invalid read of size 4
==9499==    at 0x401798: vtkObjectBase::GetReferenceCount()
(vtkObjectBase.h:143)
==9499==    by 0x4014BF: main (Cone5.cxx:111)
==9499==  Address 0x127d71d8 is 8 bytes inside a block of size 440 free'd
==9499==    at 0x4C2A4BC: operator delete(void*) (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9499==    by 0x5265837: vtkOpenGLActor::~vtkOpenGLActor()
(vtkOpenGLActor.h:42)
==9499==    by 0x781C8F0: vtkObjectBase::UnRegisterInternal(vtkObjectBase*,
int) (vtkObjectBase.cxx:286)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int)
(vtkObject.cxx:885)
==9499==    by 0x781C515: vtkObjectBase::UnRegister(vtkObjectBase*)
(vtkObjectBase.cxx:189)
==9499==    by 0x781C29B: vtkObjectBase::Delete() (vtkObjectBase.cxx:134)
==9499==    by 0x401434: main (Cone5.cxx:104)
==9499==
actor: 0
renderer: 2
render_window: 2
interactor: 2
style: 2

==9499== Invalid read of size 4
==9499==    at 0x401798: vtkObjectBase::GetReferenceCount()
(vtkObjectBase.h:143)
==9499==    by 0x401600: main (Cone5.cxx:129)
==9499==  Address 0xfbfec58 is 8 bytes inside a block of size 200 free'd
==9499==    at 0x4C2A4BC: operator delete(void*) (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9499==    by 0x637B1DF: vtkContourFilter::~vtkContourFilter()
(vtkContourFilter.cxx:95)
==9499==    by 0x781C8F0: vtkObjectBase::UnRegisterInternal(vtkObjectBase*,
int) (vtkObjectBase.cxx:286)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int)
(vtkObject.cxx:885)
==9499==    by 0x77A11F8:
vtkGarbageCollectorToObjectBaseFriendship::UnRegister(vtkObjectBase*,
vtkObjectBase*) (vtkGarbageCollector.cxx:141)
==9499==    by 0x779FB69:
vtkGarbageCollectorImpl::CollectComponent(vtkGarbageCollectorImpl::ComponentType*)
(vtkGarbageCollector.cxx:702)
==9499==    by 0x779EDE0:
vtkGarbageCollectorImpl::CollectInternal(vtkObjectBase*)
(vtkGarbageCollector.cxx:473)
==9499==    by 0x77A0A14: vtkGarbageCollector::Collect(vtkObjectBase*)
(vtkGarbageCollector.cxx:904)
==9499==    by 0x781C904: vtkObjectBase::UnRegisterInternal(vtkObjectBase*,
int) (vtkObjectBase.cxx:294)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int)
(vtkObject.cxx:885)
==9499==    by 0x6F8B8F3: vtkAlgorithm::UnRegister(vtkObjectBase*)
(vtkAlgorithm.cxx:917)
==9499==    by 0x781C29B: vtkObjectBase::Delete() (vtkObjectBase.cxx:134)
==9499==
contour: 0
==9499== Invalid read of size 4
==9499==    at 0x401798: vtkObjectBase::GetReferenceCount()
(vtkObjectBase.h:143)
==9499==    by 0x40161D: main (Cone5.cxx:130)
==9499==  Address 0xfc15e18 is 8 bytes inside a block of size 664 free'd
==9499==    at 0x4C2A4BC: operator delete(void*) (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9499==    by 0x5153D63:
vtkPainterPolyDataMapper::~vtkPainterPolyDataMapper()
(vtkPainterPolyDataMapper.cxx:96)
==9499==    by 0x781C8F0: vtkObjectBase::UnRegisterInternal(vtkObjectBase*,
int) (vtkObjectBase.cxx:286)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int)
(vtkObject.cxx:885)
==9499==    by 0x77A11F8:
vtkGarbageCollectorToObjectBaseFriendship::UnRegister(vtkObjectBase*,
vtkObjectBase*) (vtkGarbageCollector.cxx:141)
==9499==    by 0x779FB69:
vtkGarbageCollectorImpl::CollectComponent(vtkGarbageCollectorImpl::ComponentType*)
(vtkGarbageCollector.cxx:702)
==9499==    by 0x779EDE0:
vtkGarbageCollectorImpl::CollectInternal(vtkObjectBase*)
(vtkGarbageCollector.cxx:473)
==9499==    by 0x77A0A14: vtkGarbageCollector::Collect(vtkObjectBase*)
(vtkGarbageCollector.cxx:904)
==9499==    by 0x781C904: vtkObjectBase::UnRegisterInternal(vtkObjectBase*,
int) (vtkObjectBase.cxx:294)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int)
(vtkObject.cxx:885)
==9499==    by 0x6F8B8F3: vtkAlgorithm::UnRegister(vtkObjectBase*)
(vtkAlgorithm.cxx:917)
==9499==    by 0x781C29B: vtkObjectBase::Delete() (vtkObjectBase.cxx:134)
==9499==
mapper: 0
==9499== Invalid read of size 4
==9499==    at 0x401798: vtkObjectBase::GetReferenceCount()
(vtkObjectBase.h:143)
==9499==    by 0x40163A: main (Cone5.cxx:131)
==9499==  Address 0x127d71d8 is 8 bytes inside a block of size 440 free'd
==9499==    at 0x4C2A4BC: operator delete(void*) (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9499==    by 0x5265837: vtkOpenGLActor::~vtkOpenGLActor()
(vtkOpenGLActor.h:42)
==9499==    by 0x781C8F0: vtkObjectBase::UnRegisterInternal(vtkObjectBase*,
int) (vtkObjectBase.cxx:286)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int)
(vtkObject.cxx:885)
==9499==    by 0x781C515: vtkObjectBase::UnRegister(vtkObjectBase*)
(vtkObjectBase.cxx:189)
==9499==    by 0x781C29B: vtkObjectBase::Delete() (vtkObjectBase.cxx:134)
==9499==    by 0x401434: main (Cone5.cxx:104)
==9499==
actor: 0
==9499== Invalid read of size 4
==9499==    at 0x401798: vtkObjectBase::GetReferenceCount()
(vtkObjectBase.h:143)
==9499==    by 0x401657: main (Cone5.cxx:132)
==9499==  Address 0x1284a2f8 is 8 bytes inside a block of size 808 free'd
==9499==    at 0x4C2A4BC: operator delete(void*) (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9499==    by 0x52A411D: vtkOpenGLRenderer::~vtkOpenGLRenderer()
(vtkOpenGLRenderer.cxx:1278)
==9499==    by 0x781C8F0: vtkObjectBase::UnRegisterInternal(vtkObjectBase*,
int) (vtkObjectBase.cxx:286)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int)
(vtkObject.cxx:885)
==9499==    by 0x781C515: vtkObjectBase::UnRegister(vtkObjectBase*)
(vtkObjectBase.cxx:189)
==9499==    by 0x781C29B: vtkObjectBase::Delete() (vtkObjectBase.cxx:134)
==9499==    by 0x4015DD: main (Cone5.cxx:126)
==9499==
renderer: 0
==9499== Invalid read of size 4
==9499==    at 0x401798: vtkObjectBase::GetReferenceCount()
(vtkObjectBase.h:143)
==9499==    by 0x401674: main (Cone5.cxx:133)
==9499==  Address 0x1284a8b8 is 8 bytes inside a block of size 632 free'd
==9499==    at 0x4C2A4BC: operator delete(void*) (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9499==    by 0x52F5C59: vtkXOpenGLRenderWindow::~vtkXOpenGLRenderWindow()
(vtkXOpenGLRenderWindow.cxx:455)
==9499==    by 0x781C8F0: vtkObjectBase::UnRegisterInternal(vtkObjectBase*,
int) (vtkObjectBase.cxx:286)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int)
(vtkObject.cxx:885)
==9499==    by 0x781C515: vtkObjectBase::UnRegister(vtkObjectBase*)
(vtkObjectBase.cxx:189)
==9499==    by 0x51B6D56: vtkRenderWindow::UnRegister(vtkObjectBase*)
(vtkRenderWindow.cxx:1309)
==9499==    by 0x51BF26A:
vtkRenderWindowInteractor::SetRenderWindow(vtkRenderWindow*)
(vtkRenderWindowInteractor.cxx:194)
==9499==    by 0x51B6D25: vtkRenderWindow::UnRegister(vtkObjectBase*)
(vtkRenderWindow.cxx:1303)
==9499==    by 0x781C29B: vtkObjectBase::Delete() (vtkObjectBase.cxx:134)
==9499==    by 0x4015F4: main (Cone5.cxx:127)
==9499==
render_window: 0
==9499== Invalid read of size 4
==9499==    at 0x401798: vtkObjectBase::GetReferenceCount()
(vtkObjectBase.h:143)
==9499==    by 0x401691: main (Cone5.cxx:134)
==9499==  Address 0x127e70e8 is 8 bytes inside a block of size 312 free'd
==9499==    at 0x4C2A4BC: operator delete(void*) (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9499==    by 0x525253F:
vtkXRenderWindowInteractor::~vtkXRenderWindowInteractor()
(vtkXRenderWindowInteractor.cxx:147)
==9499==    by 0x781C8F0: vtkObjectBase::UnRegisterInternal(vtkObjectBase*,
int) (vtkObjectBase.cxx:286)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int)
(vtkObject.cxx:885)
==9499==    by 0x781C515: vtkObjectBase::UnRegister(vtkObjectBase*)
(vtkObjectBase.cxx:189)
==9499==    by 0x51BF203:
vtkRenderWindowInteractor::UnRegister(vtkObjectBase*)
(vtkRenderWindowInteractor.cxx:181)
==9499==    by 0x51B6D41: vtkRenderWindow::UnRegister(vtkObjectBase*)
(vtkRenderWindow.cxx:1304)
==9499==    by 0x781C29B: vtkObjectBase::Delete() (vtkObjectBase.cxx:134)
==9499==    by 0x4015F4: main (Cone5.cxx:127)
==9499==
interactor: 0
==9499== Invalid read of size 4
==9499==    at 0x401798: vtkObjectBase::GetReferenceCount()
(vtkObjectBase.h:143)
==9499==    by 0x4016AE: main (Cone5.cxx:135)
==9499==  Address 0x1284ad18 is 8 bytes inside a block of size 280 free'd
==9499==    at 0x4C2A4BC: operator delete(void*) (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9499==    by 0x50CBE9F:
vtkInteractorStyleTrackballCamera::~vtkInteractorStyleTrackballCamera()
(vtkInteractorStyleTrackballCamera.cxx:36)
==9499==    by 0x781C8F0: vtkObjectBase::UnRegisterInternal(vtkObjectBase*,
int) (vtkObjectBase.cxx:286)
==9499==    by 0x781AE56: vtkObject::UnRegisterInternal(vtkObjectBase*, int)
(vtkObject.cxx:885)
==9499==    by 0x781C515: vtkObjectBase::UnRegister(vtkObjectBase*)
(vtkObjectBase.cxx:189)
==9499==    by 0x781C29B: vtkObjectBase::Delete() (vtkObjectBase.cxx:134)
==9499==    by 0x4015AF: main (Cone5.cxx:124)
==9499==
style: 0

Done
==9499==
==9499== FILE DESCRIPTORS: 5 open at exit.
==9499== Open AF_UNIX socket 3: <unknown>
==9499==    at 0x805D757: socket (syscall-template.S:82)
==9499==    by 0xEAB80BA: ??? (in /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0)
==9499==    by 0xEAB8543: xcb_connect_to_display_with_auth_info (in
/usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0)
==9499==    by 0x9427EF1: _XConnectXCB (in
/usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==9499==    by 0x9418A40: XOpenDisplay (in
/usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==9499==    by 0x91A354E: XtOpenDisplay (in
/usr/lib/x86_64-linux-gnu/libXt.so.6.0.0)
==9499==    by 0x5252EA3: vtkXRenderWindowInteractor::Initialize()
(vtkXRenderWindowInteractor.cxx:366)
==9499==    by 0x401707: main (Cone5.cxx:141)
==9499==
==9499== Open file descriptor 9: /proc/2720/auxv
==9499==    <inherited from parent>
==9499==
==9499== Open file descriptor 2: /dev/pts/1
==9499==    <inherited from parent>
==9499==
==9499== Open file descriptor 1: /dev/pts/1
==9499==    <inherited from parent>
==9499==
==9499== Open file descriptor 0: /dev/pts/1
==9499==    <inherited from parent>
==9499==
==9499==
==9499== HEAP SUMMARY:
==9499==     in use at exit: 508,751 bytes in 2,432 blocks
==9499==   total heap usage: 32,927 allocs, 30,495 frees, 915,497,381 bytes
allocated
==9499==
==9499== LEAK SUMMARY:
==9499==    definitely lost: 262,268 bytes in 3 blocks
==9499==    indirectly lost: 176 bytes in 4 blocks
==9499==      possibly lost: 180 bytes in 5 blocks
==9499==    still reachable: 246,127 bytes in 2,420 blocks
==9499==         suppressed: 0 bytes in 0 blocks
==9499== Rerun with --leak-check=full to see details of leaked memory
==9499==
==9499== For counts of detected and suppressed errors, rerun with: -v
==9499== Use --track-origins=yes to see where uninitialised values come from
==9499== ERROR SUMMARY: 6153 errors from 13 contexts (suppressed: 2 from 2)



--
View this message in context: http://vtk.1045678.n5.nabble.com/VTK-not-releasing-memory-including-minimal-example-tp5716258p5716261.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers



--
Unpaid intern in BillsBasement at noware dot com


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: VTK not releasing memory, including minimal example.

P.J.Schaafsma
In reply to this post by David Gobbi
...and the VTK_DEBUG_LEAKS output. Seems to work. Everything is cleaned up. Still, memory use is > 100Mb during the event loop in this simple case.

Used source:


int main()
{
        vtkXMLImageDataReader *reader = vtkXMLImageDataReader::New();
        //reader->SetFileName("e:\\data\\volume\\manix_low.vti");
        reader->SetFileName("/media/Data/data/volume/manix_low.vti");

        vtkContourFilter *contour = vtkContourFilter::New();
        contour->SetInputConnection(reader->GetOutputPort());
        contour->SetValue(0, 800);

        vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
        mapper->SetInputConnection(contour->GetOutputPort());
        mapper->Update();

        vtkActor *actor = vtkActor::New();
        actor->SetMapper(mapper);

        vtkRenderer *renderer = vtkRenderer::New();
        renderer->AddActor(actor);

        vtkRenderWindow *render_window = vtkRenderWindow::New();
        render_window->AddRenderer(renderer);

        vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New();
       
        vtkRenderWindowInteractor *interactor = vtkRenderWindowInteractor::New();
        interactor->SetInteractorStyle(style);
        interactor->SetRenderWindow(render_window);
        interactor->Initialize();
         
        ////// Comment this out and save memory
        render_window->Render();
        //////
       
        renderer->RemoveActor(actor);
        render_window->Render();
       
        actor->Delete();
        mapper->Delete();
        contour->Delete();
        reader->Delete();

        interactor->Start();
       
        render_window->RemoveRenderer(renderer);
        interactor->SetInteractorStyle(0);
       
        style->Delete();
        interactor->Delete();
        renderer->Delete();
        render_window->Delete();
       
        // Just checking debug leaks works
        vtkActor *a = vtkActor::New();
       
        return 0;
}

Output


vtkDebugLeaks has detected LEAKS!
Class "vtkMatrix4x4" has 2 instances still around.
Class "vtkOpenGLActor" has 1 instance still around.
Class "vtkTransform" has 1 instance still around.


Reply | Threaded
Open this post in threaded view
|

Re: VTK not releasing memory, including minimal example.

Bill Lorensen
How big is the input image and how many triangles is ContourFilter generating?

On Sun, Sep 23, 2012 at 2:05 PM, P.J.Schaafsma <[hidden email]> wrote:
...and the VTK_DEBUG_LEAKS output. Seems to work. Everything is cleaned up.
Still, memory use is > 100Mb during the event loop in this simple case.

Used source:


int main()
{
        vtkXMLImageDataReader *reader = vtkXMLImageDataReader::New();
        //reader->SetFileName("e:\\data\\volume\\manix_low.vti");
        reader->SetFileName("/media/Data/data/volume/manix_low.vti");

        vtkContourFilter *contour = vtkContourFilter::New();
        contour->SetInputConnection(reader->GetOutputPort());
        contour->SetValue(0, 800);

        vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
        mapper->SetInputConnection(contour->GetOutputPort());
        mapper->Update();

        vtkActor *actor = vtkActor::New();
        actor->SetMapper(mapper);

        vtkRenderer *renderer = vtkRenderer::New();
        renderer->AddActor(actor);

        vtkRenderWindow *render_window = vtkRenderWindow::New();
        render_window->AddRenderer(renderer);

        vtkInteractorStyleTrackballCamera *style =
vtkInteractorStyleTrackballCamera::New();

        vtkRenderWindowInteractor *interactor = vtkRenderWindowInteractor::New();
        interactor->SetInteractorStyle(style);
        interactor->SetRenderWindow(render_window);
        interactor->Initialize();

        ////// Comment this out and save memory
        render_window->Render();
        //////

        renderer->RemoveActor(actor);
        render_window->Render();

        actor->Delete();
        mapper->Delete();
        contour->Delete();
        reader->Delete();

        interactor->Start();

        render_window->RemoveRenderer(renderer);
        interactor->SetInteractorStyle(0);

        style->Delete();
        interactor->Delete();
        renderer->Delete();
        render_window->Delete();

        // Just checking debug leaks works
        vtkActor *a = vtkActor::New();

        return 0;
}

Output


vtkDebugLeaks has detected LEAKS!
Class "vtkMatrix4x4" has 2 instances still around.
Class "vtkOpenGLActor" has 1 instance still around.
Class "vtkTransform" has 1 instance still around.






--
View this message in context: http://vtk.1045678.n5.nabble.com/VTK-not-releasing-memory-including-minimal-example-tp5716258p5716262.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers



--
Unpaid intern in BillsBasement at noware dot com


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: VTK not releasing memory, including minimal example.

P.J.Schaafsma
Mind you, the memory use itself is not the issue, it's the discrepancy! When the scene is rendered before the actor, mapper, contour, and reader are deleted, memory use during the event loop is >100Mb, if the pipeline is executed (mapper is updated) but the actor is deleted before the first render, memory use of the application is about 13Mb during the event loop.

In any case (output from python, because it prints more easily):

Volume.vti

vtkImageData (0x2d5dab0)
  Debug: Off
  Modified Time: 1564
  Reference Count: 2
  Registered Events: (none)
  Source: (none)
  Information: 0x2d5dc20
  Data Released: False
  Global Release Data: Off
  UpdateTime: 1565
  Release Data: Off
  UpdateExtent: Not Initialized
  UpdateExtent: 0, 255, 0, 229, 0, 255
  WholeExtent: 0, 255, 0, 229, 0, 255
  ExtentTranslator: (0x2d5fcc0)
  RequestExactExtent: Off
   Field Data:
    Debug: Off
    Modified Time: 1544
    Reference Count: 1
    Registered Events: (none)
    Number Of Arrays: 0
    Number Of Components: 0
    Number Of Tuples: 0
  Number Of Points: 15073280
  Number Of Cells: 14890725
  Cell Data:
    Debug: Off
    Modified Time: 1552
    Reference Count: 1
    Registered Events: (none)
    Number Of Arrays: 0
    Number Of Components: 0
    Number Of Tuples: 0
    Copy Tuple Flags: ( 1 1 1 1 1 0 1 )
    Interpolate Flags: ( 1 1 1 1 1 0 0 )
    Pass Through Flags: ( 1 1 1 1 1 1 1 )
    Scalars: (none)
    Vectors: (none)
    Normals: (none)
    TCoords: (none)
    Tensors: (none)
    GlobalIds: (none)
    PedigreeIds: (none)
  Point Data:
    Debug: Off
    Modified Time: 1559
    Reference Count: 1
    Registered Events: (none)
    Number Of Arrays: 1
    Array 0 name = MetaImage
    Number Of Components: 1
    Number Of Tuples: 15073280
    Copy Tuple Flags: ( 1 1 1 1 1 0 1 )
    Interpolate Flags: ( 1 1 1 1 1 0 0 )
    Pass Through Flags: ( 1 1 1 1 1 1 1 )
    Scalars:
      Debug: Off
      Modified Time: 1556
      Reference Count: 1
      Registered Events: (none)
      Name: MetaImage
      Data type: short
      Size: 15073280
      MaxId: 15073279
      NumberOfComponents: 1
      Information: 0
      Name: MetaImage
      Number Of Components: 1
      Number Of Tuples: 15073280
      Size: 15073280
      MaxId: 15073279
      LookupTable: (none)
      Array: 0x7f2daec87010
    Vectors: (none)
    Normals: (none)
    TCoords: (none)
    Tensors: (none)
    GlobalIds: (none)
    PedigreeIds: (none)
  Bounds:
    Xmin,Xmax: (-125, 124.023)
    Ymin,Ymax: (-858, -537.4)
    Zmin,Zmax: (-63, 186.023)
  Compute Time: 0
  ScalarType: 4
  NumberOfScalarComponents: 1
  Spacing: (0.976562, 1.4, 0.976562)
  Origin: (-125, -858, -63)
  Dimensions: (256, 230, 256)
  Increments: (0, 0, 0)
  Extent: (0, 255, 0, 229, 0, 255)


Contour output


vtkPolyData (0x2d73f00)
  Debug: Off
  Modified Time: 1854
  Reference Count: 2
  Registered Events: (none)
  Source: (none)
  Information: 0x2d74060
  Data Released: False
  Global Release Data: Off
  UpdateTime: 1855
  Release Data: Off
  UpdateExtent: Not Initialized
  Update Number Of Pieces: 1
  Update Piece: 0
  Update Ghost Level: 0
  WholeExtent: 0, 255, 0, 229, 0, 255
  MaximumNumberOfPieces: -1
  ExtentTranslator: (0x2d5fcc0)
  RequestExactExtent: Off
   Field Data:
    Debug: Off
    Modified Time: 1809
    Reference Count: 1
    Registered Events: (none)
    Number Of Arrays: 0
    Number Of Components: 0
    Number Of Tuples: 0
  Number Of Points: 292366
  Number Of Cells: 585104
  Cell Data:
    Debug: Off
    Modified Time: 1817
    Reference Count: 1
    Registered Events: (none)
    Number Of Arrays: 0
    Number Of Components: 0
    Number Of Tuples: 0
    Copy Tuple Flags: ( 1 1 1 1 1 0 1 )
    Interpolate Flags: ( 1 1 1 1 1 0 0 )
    Pass Through Flags: ( 1 1 1 1 1 1 1 )
    Scalars: (none)
    Vectors: (none)
    Normals: (none)
    TCoords: (none)
    Tensors: (none)
    GlobalIds: (none)
    PedigreeIds: (none)
  Point Data:
    Debug: Off
    Modified Time: 1854
    Reference Count: 1
    Registered Events: (none)
    Number Of Arrays: 2
    Array 0 name = MetaImage
    Array 1 name = Normals
    Number Of Components: 4
    Number Of Tuples: 292366
    Copy Tuple Flags: ( 0 1 1 1 1 1 1 )
    Interpolate Flags: ( 0 1 1 1 1 1 1 )
    Pass Through Flags: ( 0 1 1 1 1 1 1 )
    Scalars:
      Debug: Off
      Modified Time: 1848
      Reference Count: 1
      Registered Events: (none)
      Name: MetaImage
      Data type: float
      Size: 292366
      MaxId: 292365
      NumberOfComponents: 1
      Information: 0
      Name: MetaImage
      Number Of Components: 1
      Number Of Tuples: 292366
      Size: 292366
      MaxId: 292365
      LookupTable: (none)
      Array: 0x7f2dae8c1010
    Vectors: (none)
    Normals:
      Debug: Off
      Modified Time: 1844
      Reference Count: 1
      Registered Events: (none)
      Name: Normals
      Data type: float
      Size: 877098
      MaxId: 877097
      NumberOfComponents: 3
      Information: 0
      Name: Normals
      Number Of Components: 3
      Number Of Tuples: 292366
      Size: 877098
      MaxId: 877097
      LookupTable: (none)
      Array: 0x7f2dac9f3010
    TCoords: (none)
    Tensors: (none)
    GlobalIds: (none)
    PedigreeIds: (none)
  Bounds:
    Xmin,Xmax: (-105.346, 123.589)
    Ymin,Ymax: (-858, -537.4)
    Zmin,Zmax: (-24.3793, 179.238)
  Compute Time: 1870
  Number Of Points: 292366
  Point Coordinates: 0x2d70120
  Locator: 0
  Number Of Vertices: 0
  Number Of Lines: 0
  Number Of Polygons: 585104
  Number Of Triangle Strips: 0
  Number Of Pieces: 1
  Piece: 0
  Ghost Level: 0
Reply | Threaded
Open this post in threaded view
|

Re: VTK not releasing memory, including minimal example.

P.J.Schaafsma
In reply to this post by Bill Lorensen
The interactor is being deleted, but of course not when I'm still in the event loop.

Using smart pointers caused even worse memory hogging.
Reply | Threaded
Open this post in threaded view
|

Re: VTK not releasing memory, including minimal example.

P.J.Schaafsma
In reply to this post by P.J.Schaafsma
The issue is NOT confirmed on a different machine!

I am surprised by the low level of the issue this implies. Is it perhaps some caching of disk files by windows? Or a graphics driver bug by nVidia in both their Windows and Linux drivers? Perhaps a BIOS feature causing this behavior?

I do not have access to my previous machine atm, but I can say that on this machine, everything behaves as expected, and memory use during the event loop is around 7Mb.

So, on a netbook EEE1015PEB runnig win7-x86 the issue cannot be reproduced.

My other machine has the following hardware, win7-64, with the latest drivers, by my knowledge:

Intel Core i7 2600K Boxed
Asus P8Z68-V
Corsair Vengeance 8GB (2x4GB) DDR3, 1600Mhz, C9
MSI N570GTX Twin Frozr III Power Edition/OC
Western digital Caviar Green 3TB 136,80 136,80
Reply | Threaded
Open this post in threaded view
|

Re: VTK not releasing memory, including minimal example.

Bill Lorensen
Interesting. How are you measuring memory usage on Windows? If the memory just for your task?

On Sun, Sep 23, 2012 at 3:22 PM, P.J.Schaafsma <[hidden email]> wrote:
The issue is NOT confirmed on a different machine!

I am surprised by the low level of the issue this implies. Is it perhaps
some caching of disk files by windows? Or a graphics driver bug by nVidia in
both their Windows and Linux drivers? Perhaps a BIOS feature causing this
behavior?

I do not have access to my previous machine atm, but I can say that on this
machine, everything behaves as expected, and memory use during the event
loop is around 7Mb.

So, on a netbook EEE1015PEB runnig win7-x86 the issue cannot be reproduced.

My other machine has the following hardware, win7-64, with the latest
drivers, by my knowledge:

Intel Core i7 2600K Boxed
Asus P8Z68-V
Corsair Vengeance 8GB (2x4GB) DDR3, 1600Mhz, C9
MSI N570GTX Twin Frozr III Power Edition/OC
Western digital Caviar Green 3TB        136,80  136,80




--
View this message in context: http://vtk.1045678.n5.nabble.com/VTK-not-releasing-memory-including-minimal-example-tp5716258p5716267.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers



--
Unpaid intern in BillsBasement at noware dot com


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: VTK not releasing memory, including minimal example.

P.J.Schaafsma
In Windows the Task Manager

In Kubuntu, the Default System monitor, don't know it's exact name by heart.
Reply | Threaded
Open this post in threaded view
|

Re: VTK not releasing memory, including minimal example.

P.J.Schaafsma
Ok, here's the deal. It's a bug in VTK.

If you do a renderer.SetActiveCamera(vtk.vtkCamera()) before the first Render() call, all is well. If you don't, memory is being hogged.

Don't know why the issue didn't arise on my other machine.
Reply | Threaded
Open this post in threaded view
|

Re: VTK not releasing memory, including minimal example.

Bill Lorensen
I don't recall seeing this reported anywhere in the past. What platforms does this occur on?

On Mon, Sep 24, 2012 at 4:06 PM, P.J.Schaafsma <[hidden email]> wrote:
Ok, here's the deal. It's a bug in VTK.

If you do a renderer.SetActiveCamera(vtk.vtkCamera()) before the first
Render() call, all is well. If you don't, memory is being hogged.

Don't know why the issue didn't arise on my other machine.




--
View this message in context: http://vtk.1045678.n5.nabble.com/VTK-not-releasing-memory-including-minimal-example-tp5716258p5716279.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers



--
Unpaid intern in BillsBasement at noware dot com


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: VTK not releasing memory, including minimal example.

David Gobbi
In reply to this post by P.J.Schaafsma
The only thing that SetActiveCamera() does in this case is cause the
renderer to not automatically call ResetCamera() on the first render.

If you replace this line:

  renderer.SetActiveCamera(vtk.vtkCamera())

with this line:

  renderer.GetActiveCamera()

does it give exactly the same memory usage?  Either of these will
eliminate the automatic call to ResetCamera().

Also, with your valgrind run from a couple messages ago, it looks like
you just ran "valgrind" without running "valgrind --leak-check=full"
as I had recommended.  Without the "--leak-check=full", valgrind will
not tell you where the leaked memory was allocated, and that's what we
really want to know.  We want to know if the memory was allocated in
the graphics drivers, in the X11 libraries, or if was allocated in one
of the VTK libraries.

 - David



On Mon, Sep 24, 2012 at 2:06 PM, P.J.Schaafsma
<[hidden email]> wrote:
> Ok, here's the deal. It's a bug in VTK.
>
> If you do a renderer.SetActiveCamera(vtk.vtkCamera()) before the first
> Render() call, all is well. If you don't, memory is being hogged.
>
> Don't know why the issue didn't arise on my other machine.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: VTK not releasing memory, including minimal example.

P.J.Schaafsma
I'll rerun valgrind tomorrow (+1 CET here), and I'll try the camera thing too then. By the way, it seems more likely that memory is not actually lost, just being hogged by VTK.
Reply | Threaded
Open this post in threaded view
|

Re: VTK not releasing memory, including minimal example.

P.J.Schaafsma
This post was updated on .
The camera thing didn't work. Didn't rerun valgrind yet, but I don't expect any results from it, especially since the builtin VTK memory leak thing worked flawlessly. Furthermore, scouring the internet leads me to believe that this is a genuine issue of memory hogging, not leaking, which has appeared on various forums under different titles, all unsolved.


Anyway, memory use increases in several steps. This is from the python code using also the wxVTKRenderWindowInteractor. I'll type what I find as I go. Hope it helps.

Set up


After setting up, just a vtkRenderer inside a basic wxFrame, the python.exe process uses about 40Mb.

Load data


After loading the data, and running a VTK pipeline that will get me some polydata (10Mb on disk), memory use is about 130MB.

First render


After initial loading of the data, at first render, memory use is increased during vtkPolygonsPainter, lines 309 to 316 to about 180Mb:

      vtkDrawPolysMacro(primitive,
        device->SendAttribute(vtkPointData::NORMALS, 3,
          ntype, normals, 3**ptIds);
        device->SendAttribute(vtkPointData::SCALARS, 3,
          VTK_UNSIGNED_CHAR, colors + 4**ptIds);
        device->SendAttribute(vtkPointData::NUM_ATTRIBUTES, 3,
          ptype, points, 3**ptIds);,;,;);
      break;

This appears to be the memory used by a display list, as evidenced by the line 159 to 163 in vtkOpenGLDisplayListPainter.cxx, and therefore a reasonable, and vtkOpenGLDisplayListPainter::ReleaseAllList does get called when removing an actor from the renderer.

First render, continued


As far as I can track the calls to VTK, memory use doesn't increase until we get to some wx stuff, at which point it increases again to about 270Mb, but this is still before the Render call to the wxvtkinteractor from python ends. Of course, this could be related to wx or python.

Interaction


If I then leave the window be, memory stays at 270Mb, but when I start zooming or rotating, it increases again to over 400Mb.

So, in the end, displaying a simple 500k triangle mesh takes up over 400Mb of memory. Now that's excessive! After I delete the actor, and remove all python objects, even the renderer!!, memory use is still 270Mb.
Reply | Threaded
Open this post in threaded view
|

Re: VTK not releasing memory, including minimal example.

P.J.Schaafsma
Problem is the same when using a Qt interactor, so Wx doesn't appear to be a factor here.
Reply | Threaded
Open this post in threaded view
|

Re: VTK not releasing memory, including minimal example.

P.J.Schaafsma
Pure C++ shows the same problems, so Python isn't a factor either.

C++ code


#include <stdio.h>
#include <crtdbg.h>

#include "vtkConeSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkCamera.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkContourFilter.h"
#include "vtkXMLImageDataReader.h"
#include "vtkPolyDataMapper.h"
#include "vtkCallbackCommand.h"

void middle(vtkObject*, unsigned long eid, void* clientdata, void *calldata)
{
        void **data = (void **)clientdata;

        vtkXMLImageDataReader *reader = (vtkXMLImageDataReader *)data[0];
        vtkContourFilter *contour = (vtkContourFilter *)data[1];
        vtkPolyDataMapper *mapper = (vtkPolyDataMapper *)data[2];
        vtkActor *actor = (vtkActor *)data[3];
        vtkRenderer *renderer = (vtkRenderer *)data[4];

        renderer->RemoveActor(actor);

        printf("actor RC: %d\n", actor->GetReferenceCount());
        printf("mapper RC: %d\n", mapper->GetReferenceCount());
        printf("contour RC: %d\n", contour->GetReferenceCount());
        printf("reader RC: %d\n", reader->GetReferenceCount());
       
        actor->Delete();
        mapper->Delete();
        contour->Delete();
        reader->Delete();

        printf("actor RC: %d\n", actor->GetReferenceCount());
        printf("mapper RC: %d\n", mapper->GetReferenceCount());
        printf("contour RC: %d\n", contour->GetReferenceCount());
        printf("reader RC: %d\n", reader->GetReferenceCount());

}

void right(vtkObject*, unsigned long eid, void* clientdata, void *calldata)
{
        void **data = (void **)clientdata;

        vtkXMLImageDataReader *reader = (vtkXMLImageDataReader *)data[0];
        vtkContourFilter *contour = (vtkContourFilter *)data[1];
        vtkPolyDataMapper *mapper = (vtkPolyDataMapper *)data[2];
        vtkActor *actor = (vtkActor *)data[3];
        vtkRenderer *renderer = (vtkRenderer *)data[4];

        reader->SetFileName("e:\\data\\volume\\manix_low.vti");
        //reader->SetFileName("/media/Data/data/volume/manix_low.vti");

        contour->SetInputConnection(reader->GetOutputPort());
        contour->SetValue(0, 800);

        mapper->SetInputConnection(contour->GetOutputPort());

        actor->SetMapper(mapper);

        renderer->AddActor(actor);
        renderer->ResetCamera();

}

int main()
{
        vtkCamera *camera = vtkCamera::New();

        vtkRenderer *renderer = vtkRenderer::New();
        renderer->SetActiveCamera(camera);

        vtkRenderWindow *render_window = vtkRenderWindow::New();
        render_window->AddRenderer(renderer);

        vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New();
       
        vtkRenderWindowInteractor *interactor = vtkRenderWindowInteractor::New();
        interactor->SetInteractorStyle(style);
        interactor->SetRenderWindow(render_window);
        interactor->Initialize();

        vtkXMLImageDataReader *reader = vtkXMLImageDataReader::New();
        vtkContourFilter *contour = vtkContourFilter::New();
        vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
        vtkActor *actor = vtkActor::New();

        void *data[] = {reader, contour, mapper, actor, renderer};

        vtkCallbackCommand *middle_callback = vtkCallbackCommand::New();
        middle_callback->SetCallback(middle);
        middle_callback->SetClientData(data);

        vtkCallbackCommand *right_callback = vtkCallbackCommand::New();
        right_callback->SetCallback(right);
        right_callback->SetClientData(data);

        interactor->AddObserver("MiddleButtonPressEvent", middle_callback);
        interactor->AddObserver("RightButtonPressEvent", right_callback);

        interactor->Start();

        render_window->RemoveRenderer(renderer);
        interactor->SetInteractorStyle(0);
       
        style->Delete();
        camera->Delete();
        interactor->Delete();
        renderer->Delete();
        render_window->Delete();

        return 0;
}
Reply | Threaded
Open this post in threaded view
|

Re: VTK not releasing memory, including minimal example.

Alex Malyushytskyy
Pure C++ shows that you did not call Delete for at least:

        vtkCallbackCommand *middle_callback = vtkCallbackCommand::New();
        vtkCallbackCommand *right_callback = vtkCallbackCommand::New();

Make sure every ::New() is paired with Delete or use smart pointers.
I have no experience with Python but I tell you that for about 10
years of using vtk
I found a single memory leak in it, so look for a problem ion your code first.

Alex


On Sun, Sep 30, 2012 at 2:38 PM, P.J.Schaafsma
<[hidden email]> wrote:

> Pure C++ shows the same problems, so Python isn't a factor either.
>
> C++ code
>
>
> #include <stdio.h>
> #include <crtdbg.h>
>
> #include "vtkConeSource.h"
> #include "vtkPolyDataMapper.h"
> #include "vtkRenderWindow.h"
> #include "vtkRenderWindowInteractor.h"
> #include "vtkCamera.h"
> #include "vtkActor.h"
> #include "vtkRenderer.h"
> #include "vtkInteractorStyleTrackballCamera.h"
> #include "vtkContourFilter.h"
> #include "vtkXMLImageDataReader.h"
> #include "vtkPolyDataMapper.h"
> #include "vtkCallbackCommand.h"
>
> void middle(vtkObject*, unsigned long eid, void* clientdata, void *calldata)
> {
>         void **data = (void **)clientdata;
>
>         vtkXMLImageDataReader *reader = (vtkXMLImageDataReader *)data[0];
>         vtkContourFilter *contour = (vtkContourFilter *)data[1];
>         vtkPolyDataMapper *mapper = (vtkPolyDataMapper *)data[2];
>         vtkActor *actor = (vtkActor *)data[3];
>         vtkRenderer *renderer = (vtkRenderer *)data[4];
>
>         renderer->RemoveActor(actor);
>
>         printf("actor RC: %d\n", actor->GetReferenceCount());
>         printf("mapper RC: %d\n", mapper->GetReferenceCount());
>         printf("contour RC: %d\n", contour->GetReferenceCount());
>         printf("reader RC: %d\n", reader->GetReferenceCount());
>
>         actor->Delete();
>         mapper->Delete();
>         contour->Delete();
>         reader->Delete();
>
>         printf("actor RC: %d\n", actor->GetReferenceCount());
>         printf("mapper RC: %d\n", mapper->GetReferenceCount());
>         printf("contour RC: %d\n", contour->GetReferenceCount());
>         printf("reader RC: %d\n", reader->GetReferenceCount());
>
> }
>
> void right(vtkObject*, unsigned long eid, void* clientdata, void *calldata)
> {
>         void **data = (void **)clientdata;
>
>         vtkXMLImageDataReader *reader = (vtkXMLImageDataReader *)data[0];
>         vtkContourFilter *contour = (vtkContourFilter *)data[1];
>         vtkPolyDataMapper *mapper = (vtkPolyDataMapper *)data[2];
>         vtkActor *actor = (vtkActor *)data[3];
>         vtkRenderer *renderer = (vtkRenderer *)data[4];
>
>         reader->SetFileName("e:\\data\\volume\\manix_low.vti");
>         //reader->SetFileName("/media/Data/data/volume/manix_low.vti");
>
>         contour->SetInputConnection(reader->GetOutputPort());
>         contour->SetValue(0, 800);
>
>         mapper->SetInputConnection(contour->GetOutputPort());
>
>         actor->SetMapper(mapper);
>
>         renderer->AddActor(actor);
>         renderer->ResetCamera();
>
> }
>
> int main()
> {
>         vtkCamera *camera = vtkCamera::New();
>
>         vtkRenderer *renderer = vtkRenderer::New();
>         renderer->SetActiveCamera(camera);
>
>         vtkRenderWindow *render_window = vtkRenderWindow::New();
>         render_window->AddRenderer(renderer);
>
>         vtkInteractorStyleTrackballCamera *style =
> vtkInteractorStyleTrackballCamera::New();
>
>         vtkRenderWindowInteractor *interactor = vtkRenderWindowInteractor::New();
>         interactor->SetInteractorStyle(style);
>         interactor->SetRenderWindow(render_window);
>         interactor->Initialize();
>
>         vtkXMLImageDataReader *reader = vtkXMLImageDataReader::New();
>         vtkContourFilter *contour = vtkContourFilter::New();
>         vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
>         vtkActor *actor = vtkActor::New();
>
>         void *data[] = {reader, contour, mapper, actor, renderer};
>
>         vtkCallbackCommand *middle_callback = vtkCallbackCommand::New();
>         middle_callback->SetCallback(middle);
>         middle_callback->SetClientData(data);
>
>         vtkCallbackCommand *right_callback = vtkCallbackCommand::New();
>         right_callback->SetCallback(right);
>         right_callback->SetClientData(data);
>
>         interactor->AddObserver("MiddleButtonPressEvent", middle_callback);
>         interactor->AddObserver("RightButtonPressEvent", right_callback);
>
>         interactor->Start();
>
>         render_window->RemoveRenderer(renderer);
>         interactor->SetInteractorStyle(0);
>
>         style->Delete();
>         camera->Delete();
>         interactor->Delete();
>         renderer->Delete();
>         render_window->Delete();
>
>         return 0;
> }
>
>
>
>
> --
> View this message in context: http://vtk.1045678.n5.nabble.com/VTK-not-releasing-memory-including-minimal-example-tp5716258p5716368.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: VTK not releasing memory, including minimal example.

P.J.Schaafsma
Do you really think that not deleting the callbacks causes this memory hogging?! From all your 10 years of experience with vtk?!

Anyway, I've looked into in further, and it might all come down to nVidia GPU memory management, which keeps display lists and memory buffers allocated until they are specifically overwritten or their memory otherwise needed.

That would explain why the problems didn't show up on my netbook.
12