[vtkusers] release memory allocated in vtk from python

Jothybasu Selvaraj jothybasu at gmail.com
Mon Jul 2 14:12:40 EDT 2012


Won't the auto garbage collection/ memory management in python manage this?

On Mon, Jul 2, 2012 at 7:05 PM, David Gobbi <david.gobbi at gmail.com> wrote:

> 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
> _______________________________________________
> 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
>



-- 
Jothybasu Selvaraj
PhD Student
University of Liverpool
UK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120702/20ba7f7a/attachment.htm>


More information about the vtkusers mailing list