<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle18
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.EmailStyle19
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=SK link="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US'>Hi Elvis,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US'>I noticed the same behavior before ( here is the topic <a href="http://vtk.1045678.n5.nabble.com/memory-leak-in-vtkStructuredPoints-or-am-I-doing-something-wrong-tt5738805.html">http://vtk.1045678.n5.nabble.com/memory-leak-in-vtkStructuredPoints-or-am-I-doing-something-wrong-tt5738805.html</a> )<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US'>Looks like it is the standard behavior of Linux (although very weird), since this is not happening in Windows or OS X.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US'>Best,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US'>Robert<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'> vtkusers [mailto:vtkusers-bounces@vtk.org] <b>On Behalf Of </b>Elvis Stansvik<br><b>Sent:</b> Wednesday, August 31, 2016 5:19 PM<br><b>To:</b> VTK Users <vtkusers@vtk.org><br><b>Subject:</b> [vtkusers] Memory not released when volumes are removed<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><div><div><div><div><div><div><div><div><div><div><div><p class=MsoNormal style='margin-bottom:12.0pt'>Hi all,<o:p></o:p></p></div><p class=MsoNormal style='margin-bottom:12.0pt'>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).<o:p></o:p></p></div><p class=MsoNormal style='margin-bottom:12.0pt'>What I tried was<br><br> // Remove all existing volumes<br> auto volumes = renderer()->GetVolumes();<br> volumes->InitTraversal();<br> for (int i = 0; i < volumes->GetNumberOfItems(); ++i) {<br> qDebug() << "removing volume";<br> vtkSmartPointer<vtkVolume> volume = volumes->GetNextVolume();<br> qDebug() << "before:" << volume->GetReferenceCount();<br> renderer()->RemoveVolume(volume.GetPointer());<br> qDebug() << "after:" << volume->GetReferenceCount();<br> }<o:p></o:p></p></div><p class=MsoNormal style='margin-bottom:12.0pt'>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:<br><br>removing volume<br>before: 3<br>after: 1<br>removing volume<br>before: 3<br>after: 1<br>removing volume<br>before: 3<br>after: 1<o:p></o:p></p></div><p class=MsoNormal style='margin-bottom:12.0pt'>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.<o:p></o:p></p></div><p class=MsoNormal style='margin-bottom:12.0pt'>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.<o:p></o:p></p></div><p class=MsoNormal style='margin-bottom:12.0pt'>But looking at the memory usage when repeatedly loading datasets (and thus clearing the previous), the resident memory used by the app accumulates.<o:p></o:p></p></div><p class=MsoNormal style='margin-bottom:12.0pt'>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.<o:p></o:p></p></div><p class=MsoNormal style='margin-bottom:12.0pt'>Helpful for any tips on why this cleanup is apparently not enough to avoid memory accumulation.<o:p></o:p></p></div><p class=MsoNormal>Thanks,<o:p></o:p></p></div><p class=MsoNormal>Elvis<o:p></o:p></p></div></div></body></html>