[vtkusers] release memory allocated in vtk from python
David Gobbi
david.gobbi at gmail.com
Mon Jul 2 14:05:14 EDT 2012
A shallow copy should be sufficient:
def test(filename):
r = vtkgdcm.vtkGDCMImageReader()
r.SetFileName(filename)
r.Update()
img = vtk.vtkImageData()
img.ShallowCopy(r.GetOutput())
return img
Or, to be even more minimalist, copy just the pixel data and nothing else:
def test(filename):
r = vtkgdcm.vtkGDCMImageReader()
r.SetFileName(filename)
r.Update()
img = vtk.vtkImageData()
img.CopyStructure(r.GetOutput())
img.GetPointData().PassData(r.GetOutput().GetPointData())
return img
- David
On Mon, Jul 2, 2012 at 10:17 AM, Jothy <jothybasu at gmail.com> wrote:
> I think the first one.
>
> Jothy
>
> On 02-Jul-2012, at 5:06 PM, José M. Rodriguez Bacallao <jmrbcu at gmail.com> wrote:
>
>> hi folks, how to correctly release memory using vtk from python
>> for example, which one of this three code snnipets release the memory
>> allocated when reading the file:
>>
>> def test(filename):
>> r = vtkgdcm.vtkGDCMImageReader()
>> r.SetFileName(filename)
>> r.Update()
>> img = vtk.vtkImageData()
>> img.DeepCopy(r.GetOutput())
>> return img
>> --------------------------------------------------------------------------
>> def test(filename):
>> r = vtkgdcm.vtkGDCMImageReader()
>> r.SetFileName(filename)
>> r.Update()
>> return r.GetOutput()
>> ---------------------------------------------------------------------------
>> r = vtkgdcm.vtkGDCMImageReader()
>> r.SetFileName(filename)
>> r.Update()
>> img = r.GetOutput()
>> img = None
>> del img
>> r = None
>> del r
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list