<div dir="ltr">Won'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"><<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>></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 <<a href="mailto:jothybasu@gmail.com">jothybasu@gmail.com</a>> wrote:<br>
> I think the first one.<br>
><br>
> Jothy<br>
><br>
> On 02-Jul-2012, at 5:06 PM, José M. Rodriguez Bacallao <<a href="mailto:jmrbcu@gmail.com">jmrbcu@gmail.com</a>> wrote:<br>
><br>
>> hi folks, how to correctly release memory using vtk from python<br>
>> for example, which one of this three code snnipets release the memory<br>
>> allocated when reading the file:<br>
>><br>
>> def test(filename):<br>
>> r = vtkgdcm.vtkGDCMImageReader()<br>
>> r.SetFileName(filename)<br>
>> r.Update()<br>
>> img = vtk.vtkImageData()<br>
>> img.DeepCopy(r.GetOutput())<br>
>> return img<br>
>> --------------------------------------------------------------------------<br>
>> def test(filename):<br>
>> r = vtkgdcm.vtkGDCMImageReader()<br>
>> r.SetFileName(filename)<br>
>> r.Update()<br>
>> return r.GetOutput()<br>
>> ---------------------------------------------------------------------------<br>
>> r = vtkgdcm.vtkGDCMImageReader()<br>
>> r.SetFileName(filename)<br>
>> r.Update()<br>
>> img = r.GetOutput()<br>
>> img = None<br>
>> del img<br>
>> r = None<br>
>> del r<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>
> 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>
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>