<div dir="ltr">Won&#39;t the auto garbage collection/ memory management in python manage this?<br><br><div class="gmail_quote">On Mon, Jul 2, 2012 at 7:05 PM, David Gobbi <span dir="ltr">&lt;<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">A shallow copy should be sufficient:<br>
<div class="im"><br>
def test(filename):<br>
   r = vtkgdcm.vtkGDCMImageReader()<br>
   r.SetFileName(filename)<br>
   r.Update()<br>
   img = vtk.vtkImageData()<br>
</div>   img.ShallowCopy(r.GetOutput())<br>
   return img<br>
<br>
Or, to be even more minimalist, copy just the pixel data and nothing else:<br>
<div class="im"><br>
def test(filename):<br>
   r = vtkgdcm.vtkGDCMImageReader()<br>
   r.SetFileName(filename)<br>
   r.Update()<br>
   img = vtk.vtkImageData()<br>
</div>   img.CopyStructure(r.GetOutput())<br>
   img.GetPointData().PassData(r.GetOutput().GetPointData())<br>
   return img<br>
<span class="HOEnZb"><font color="#888888"><br>
 - David<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Mon, Jul 2, 2012 at 10:17 AM, Jothy &lt;<a href="mailto:jothybasu@gmail.com">jothybasu@gmail.com</a>&gt; wrote:<br>
&gt; I think the first one.<br>
&gt;<br>
&gt; Jothy<br>
&gt;<br>
&gt; On 02-Jul-2012, at 5:06 PM, José M. Rodriguez Bacallao &lt;<a href="mailto:jmrbcu@gmail.com">jmrbcu@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; hi folks, how to correctly release memory using vtk from python<br>
&gt;&gt; for example, which one of this three code snnipets release the memory<br>
&gt;&gt; allocated when reading the file:<br>
&gt;&gt;<br>
&gt;&gt; def test(filename):<br>
&gt;&gt;    r = vtkgdcm.vtkGDCMImageReader()<br>
&gt;&gt;    r.SetFileName(filename)<br>
&gt;&gt;    r.Update()<br>
&gt;&gt;    img = vtk.vtkImageData()<br>
&gt;&gt;    img.DeepCopy(r.GetOutput())<br>
&gt;&gt;    return img<br>
&gt;&gt; --------------------------------------------------------------------------<br>
&gt;&gt; def test(filename):<br>
&gt;&gt;    r = vtkgdcm.vtkGDCMImageReader()<br>
&gt;&gt;    r.SetFileName(filename)<br>
&gt;&gt;    r.Update()<br>
&gt;&gt;    return r.GetOutput()<br>
&gt;&gt; ---------------------------------------------------------------------------<br>
&gt;&gt; r = vtkgdcm.vtkGDCMImageReader()<br>
&gt;&gt; r.SetFileName(filename)<br>
&gt;&gt; r.Update()<br>
&gt;&gt; img = r.GetOutput()<br>
&gt;&gt; img = None<br>
&gt;&gt; del img<br>
&gt;&gt; r = None<br>
&gt;&gt; del r<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;&gt;<br>
&gt;&gt; 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>
&gt;&gt;<br>
&gt;&gt; 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>
&gt;&gt;<br>
&gt;&gt; Follow this link to subscribe/unsubscribe:<br>
&gt;&gt; <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
&gt; _______________________________________________<br>
&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;<br>
&gt; 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>
&gt;<br>
&gt; 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>
&gt;<br>
&gt; Follow this link to subscribe/unsubscribe:<br>
&gt; <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><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>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr">Jothybasu Selvaraj<br>PhD Student<br>University of Liverpool<br>UK<br></div><br>
</div>