[Insight-developers] Mismatched new - free (freeing images in VTK created by ITK)

Bill Lorensen bill.lorensen at gmail.com
Mon Aug 27 08:09:46 EDT 2007


Karthik,

The vtkDataArray method SetArray has a third argument (save) that when set
to 1 stops the DataArray class from deleting the array during cleanup. If
you have allocated the memory in itk, then you should set this argument to
1. Then you must delete the memory in your application.

Bill


On 8/24/07, Sean McBride <sean at rogue-research.com> wrote:
>
> On 8/23/07 12:48 PM, Karthik Krishnan said:
>
> >An itk::VectorImage is passed through as a vtkImageData grabbing the
> >internal pointer.
> >
> >Valgrind is groaning about mismatching a new with a free.  The issue is
> that
> >ITK images (see itk::ImportImageContainer) allocate/deallocate memory
> with
> >"new/delete".  VTK images (see vtkDataArrayTemplate) free memory with
> >"malloc/free". Google tells me that you may be able to get away with this
> on
> >some platforms, but it is not guarenteed to work.
> >
> >Is there a solution to this or should I just be ignoring this ?
>
> Well, since no one else has said anything.... It seems to me you have
> found a hard-to-find bug/design flaw, I would definitely fix it!
>
> I don't know that code, so I don't have many useful suggestions.  But
> why is one class deleting memory alloced by another?  Why is
> itk::VectorImage caching a private internal pointer?  Maybe copy it
> instead?  Maybe increase the vtkImageData object's ref count?
>
> --
> ____________________________________________________________
> Sean McBride, B. Eng                 sean at rogue-research.com
> Rogue Research                        www.rogue-research.com
> Mac Software Developer              Montréal, Québec, Canada
>
>
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at itk.org
> http://www.itk.org/mailman/listinfo/insight-developers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.itk.org/mailman/private/insight-developers/attachments/20070827/9775ccbe/attachment.html


More information about the Insight-developers mailing list