[vtkusers] Memory not released when volumes are removed

Elvis Stansvik elvis.stansvik at orexplore.com
Wed Aug 31 11:18:45 EDT 2016

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

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/907dbb48/attachment.html>

More information about the vtkusers mailing list