[vtkusers] Memory not released when volumes are removed

Elvis Stansvik elvis.stansvik at orexplore.com
Wed Aug 31 11:51:16 EDT 2016


HI Robert,

Den 31 aug. 2016 5:30 em skrev "Róbert Špir" <spir.robert at gmail.com>:
>
> 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.

Ah right, now I remember your post. I'll do some more testing to verify
that this is actually what's happening in my case, but it likely is.

Thanks,
Elvis

>
> Best,
>
> Robert
>
>
>
> 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();
>     volumes->InitTraversal();
>     for (int i = 0; i < volumes->GetNumberOfItems(); ++i) {
>         qDebug() << "removing volume";
>         vtkSmartPointer<vtkVolume> volume = volumes->GetNextVolume();
>         qDebug() << "before:" << volume->GetReferenceCount();
>         renderer()->RemoveVolume(volume.GetPointer());
>         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.
>
> Thanks,
>
> Elvis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160831/f34c15a6/attachment.html>


More information about the vtkusers mailing list