[Insight-users] Releasing a FileReader releases the PixelContainer of already-read images?

Gaetan Lehmann gaetan.lehmann at jouy.inra.fr
Mon Jan 16 02:56:18 EST 2006


On Monday 16 January 2006 08:02, Karthik Krishnan wrote:
> On Sun, 2006-01-15 at 20:26 -0800, Zachary Pincus wrote:
> > Hello friends,
> >
> > I've run into a troublesome issue while working on these new ITK
> > wrappers.
> >
> > The problem is thus: say that I create a FileReader object, pass it a
> > valid file name, Update() it, and get the output image. Now, if the
> > FileReader is deallocated, it seems that the PixelContainer for the
> > output image is also deallocated, leaving me with an invalid image.
> >
> > Is this default ITK behavior? If so, how can that behavior be turned
> > off? In general (not just in the ImageFileReader/ImageSource case)
> > does deallocating ITK filters also deallocate the PixelContainers of
> > the images that they generate?
> >
> > If this is not default behavior, I guess I have some bug-hunting to
> > do in the wrappers.
> >
> > Zach
> >
> > PS. Here's an example from python:
> >  >>> import itk
> >  >>> infile='/Users/zpincus/Pictures/hamster.jpg'
> >  >>> reader=itk.ImageFileReader[itk.Image[itk.US,2]].New
> >
> > (FileName=infile)
> >
> >  >>> reader.Update()
> >  >>> image=reader.GetOutput()
> >  >>> image.GetPixelContainer() != None #test for null pixel container
> >
> > True
> >
> >  >>> del(reader)
> >  >>> image.GetPixelContainer() != None
> >
> > False
> >
> > Thus we can see that when I deallocate the reader, something happens
> > to deallocate the pixel container.
>
> Replace
>   image = reader.GetOutput()
> with
>   image = itkImageUS2_Pointer(reader.GetOutput())
>
> If image was a smart pointer, this wouldn't happen cause the reference
> count will prevent it from disappearing when reader is deleted.
>
> By default the type of the return type, "image" is going to be whatever
> GetOutput() returns, which turns out to be a normal pointer, not a smart
> pointer.
>
> -karthik
>
> PS: If your intention of deleting objects is to save memory, you might
> want to use the ReleaseDataFlagOn() method. Not that your case is any
> different, from what ReleaseDataFlag would achieve, but it saves the
> headache of remembering to delete objects.
>

Ok, but this is not what a python user expect :-(
With a typemap, it should be possible to return a smart pointer instead of a 
pointer, and to pass a pointer instead of the smart pointer when it's needed 
(in SetInput() method for example).

Would there be any problem if I do that ?

Gaetan


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/insight-users/attachments/20060116/2b354d77/attachment.pgp


More information about the Insight-users mailing list