[vtkusers] Memory not released when volumes are removed

Róbert Špir spir.robert at gmail.com
Wed Aug 31 11:30:52 EDT 2016

Hi Elvis,

I noticed the same behavior before ( here is the topic http://vtk.1045678.n5.nabble.com/memory-leak-in-vtkStructuredPoints-or-am-I-doing-something-wrong-tt5738805.html )

Looks like it is the standard behavior of Linux (although very weird), since this is not happening in Windows or OS X.




From: vtkusers [mailto:vtkusers-bounces at vtk.org] On Behalf Of Elvis Stansvik
Sent: Wednesday, August 31, 2016 5:19 PM
To: VTK Users <vtkusers at vtk.org>
Subject: [vtkusers] Memory not released when volumes are removed


Hi all,

Before loading a new dataset into our app, I'd like to remove all existing volumes from the renderer, which I believe should lead to them being destroyed as well, since I have no other references to the volumes (currently).

What I tried was

    // Remove all existing volumes
    auto volumes = renderer()->GetVolumes();
    for (int i = 0; i < volumes->GetNumberOfItems(); ++i) {
        qDebug() << "removing volume";
        vtkSmartPointer<vtkVolume> volume = volumes->GetNextVolume();
        qDebug() << "before:" << volume->GetReferenceCount();
        qDebug() << "after:" << volume->GetReferenceCount();

The output I get each time I load a new dataset (actually the same, but doing it repeatedly) and execution passes by this cleanup code is:

removing volume
before: 3
after: 1
removing volume
before: 3
after: 1
removing volume
before: 3
after: 1

Which sort of makes sense to me: Apparently the renderer holds two references to the volume, since the refcount goes down by 2 when I remove the volume from the renderer. The remaining reference is held by the vtkSmartPointer I created inside the loop.

But, what surprises me is that memory usage does not seem to go down when this code is executed. I would expect that when the scope of the for loop body is exited, the refcount will drop to zero, so the volume should be deleted. And I guess it probably is.

But looking at the memory usage when repeatedly loading datasets (and thus clearing the previous), the resident memory used by the app accumulates.

Must I somehow remove the mapper / underlying image data as well? I'm not holding any references to these, so I would have expected them to die along with the volume.

Helpful for any tips on why this cleanup is apparently not enough to avoid memory accumulation.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160831/0624feb5/attachment.html>

More information about the vtkusers mailing list