<div dir="ltr"><div><div><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic">Try to add<br></span><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic">SetSource(NULL);<br>
</span></span></span></div><div><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic">calls after you register polydata<br>
</span></span></span></div><div><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><br>
</span></span>polydata->Register(NULL);<br></span><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic">polydata</span><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic">->SetSource(NULL);</span></span><br>
.....<br><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic">output->Register(NULL);<br></span><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic">output->SetSource(NULL);<br>
<br></span></span></div><div><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic">Another source of extra memory usage may be memory granularity,<br>
</span></span></div><div><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic">If you say that DeepCopy helps it means deleting/allocationg memory at the same and bugger chunks helps to avoid granularity.<br>
</span></span></div><div><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic">In this case nothing you can do.<br>
<br><br></span></span><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic">In any case I would suggest to get <br>
<br></span></span><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="white-space:pre-wrap">        </span>vtkTransformPolyDataFilter * trFilter = vtkTransformPolyDataFilter::New();<br>
<br></span></span></span></div><div><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic">and<br>
</span></span></span><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="white-space:pre-wrap"></span> trFilter->Delete();</span><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"></span></span></div>
<div><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic">out of loop.<br>
</span></span></div><div><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><br>
<br></span></span></div><div><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic">Regards,<br>
</span></span></div><div><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"> Alex<br>
</span></span></div><div><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><br>
</span></span></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jul 4, 2013 at 12:33 AM, Malsoaz James <span dir="ltr"><<a href="mailto:jmalsoaz@yahoo.fr" target="_blank">jmalsoaz@yahoo.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:10pt;font-family:Courier New,courier,monaco,monospace,sans-serif"><div style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:10pt">
Hi,</div><div style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:10pt"><br></div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:'Courier New',courier,monaco,monospace,sans-serif">
I'm experiencing troubles when copying pointers of VTK object.</div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:'Courier New',courier,monaco,monospace,sans-serif"><br>
</div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:'Courier New',courier,monaco,monospace,sans-serif">Let's say I want to apply
transformation to a polydata recursively like this:</div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:'Courier New',courier,monaco,monospace,sans-serif"><br></div><div style="font-size:13px;background-color:transparent;font-family:'Courier New',courier,monaco,monospace,sans-serif">
<span style="font-style:italic"> //Read STL</span></div><div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"> vtkSTLReader * reader = vtkSTLReader::New();</span></div>
<div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"> reader->SetFileName("1.stl");</span></div><div style="background-color:transparent">
<span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"> reader->Update();</span></div><div style="background-color:transparent"><span style="font-style:italic"><br>
</span></div><div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"> vtkPolyData * polydata = reader->GetOutput();</span></div>
<div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"> polydata->Register(NULL);</span></div><div style="background-color:transparent">
<span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"> reader->Delete();</span></div><div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><br>
</span></div><div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"> vtkTransform * tr = vtkTransform::New();</span></div>
<div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"> tr->Translate(5, 10, 1);</span></div><div style="background-color:transparent">
<span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"> tr->Update();</span></div><div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><br>
</span></div><div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"> for(int i = 0 ; i < 1000 ; ++i)</span></div>
<div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"> {</span></div><div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"> <span style="white-space:pre-wrap">        </span>std::cout << i << std::endl;</span></div>
<div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"> <span style="white-space:pre-wrap">
        </span>vtkTransformPolyDataFilter * trFilter = vtkTransformPolyDataFilter::New();</span></div><div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="white-space:pre-wrap">        </span>trFilter->SetInput(polydata);</span></div>
<div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="white-space:pre-wrap">        </span>trFilter->SetTransform(tr);</span></div>
<div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="white-space:pre-wrap">        </span>trFilter->Update();</span></div>
<div style="background-color:transparent"><span><br></span></div><div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="white-space:pre-wrap">        </span>vtkPolyData * output = trFilter->GetOutput();</span></div>
<div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="white-space:pre-wrap">        </span>output->Register(NULL);</span></div>
<div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="white-space:pre-wrap">        </span>trFilter->Delete();</span></div>
<div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><br></span></div><div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="white-space:pre-wrap">        </span>polydata->Delete();</span></div>
<div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="white-space:pre-wrap">        </span>polydata = output;</span></div>
<div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"> }</span></div><div style="background-color:transparent"><span style="font-style:italic"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;background-color:transparent"> tr->Delete();</span><br>
</span></div><div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"> polydata->Delete();</span></div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:'Courier New',courier,monaco,monospace,sans-serif">
<span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px"><br></span></div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:'Courier New',courier,monaco,monospace,sans-serif">
This is working fine and I have no VTK leaks. Unfortunately, I'm noticing that memory for my program increases instead of remaining constant.</div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:'Courier New',courier,monaco,monospace,sans-serif">
What's wrong with theses few lines?</div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:'Courier New',courier,monaco,monospace,sans-serif"><br></div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:'Courier New',courier,monaco,monospace,sans-serif">
By the way, using DeepCopy to save output data is working:</div><div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px"><span style="white-space:pre-wrap">        </span><span style="font-style:italic">polydata = vtkPolyData::New();</span></span></div>
<div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="white-space:pre-wrap">        </span>polydata->DeepCopy(output);</span></div>
<div style="background-color:transparent"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px;font-style:italic"><span style="white-space:pre-wrap">        </span>output->Delete();</span></div>
<div style="font-style:normal;font-size:13px;background-color:transparent;font-family:'Courier New',courier,monaco,monospace,sans-serif"><span style="font-family:'Courier New',courier,monaco,monospace,sans-serif;font-size:13px">But I would like to avoid to deep copy data when I only need to add a reference to the pointer. I also would like to avoid the use of vtkSmartPointer.</span></div>
<div style="font-style:normal;font-size:13px;background-color:transparent;font-family:'Courier New',courier,monaco,monospace,sans-serif"><br></div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:'Courier New',courier,monaco,monospace,sans-serif">
Thank you for your help</div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:'Courier New',courier,monaco,monospace,sans-serif">Best.</div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:'Courier New',courier,monaco,monospace,sans-serif">
<br></div></div></div><br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br></div>