[vtkusers] Memory leaks using vtk filters

Karthik Krishnan karthik.krishnan at kitware.com
Tue Feb 9 12:41:55 EST 2010


On Tue, Feb 9, 2010 at 10:01 AM, Hans Gruendel <hans.gruendel at web.de> wrote:
> Hello All,
>
> after using vtk quite often in complex projects I run into trouble with
> memory leaks. Thus my question is:
>
> How to reuse data produced by vtkAlgorithms after having deleted the
> producing algorithm?
>
> Is the following procedure right?

Yes. Shallow copy is tantamount to disconnecting the pipeline
information and copying references (ie shallow copy) to the underlying
bulk data.

>
> vtkPolyData * UtilsClass::cutIsoValue(vtkUnstructuredGrid Block, double
> IsoValue)
> {
>  vtkContourFilter * cF = vtkContourFilter::New();
>  cF->SetInputConnection(Block->GetProducerPort());
>  cF->SetValue(0,IsoValue);
>  cF->Update();
>
>  vtkPolyData * PolyData = vtkPolyData::New();
>  PolyData->ShallowCopy( cF->GetOutput() );
>
>  cF->Delete();
>
>  return PolyData;
> }
>
> and the calling function
> {
> vtkPolyData* ResultPolyData = UtilsClass::cutIsoValue(Block, Isovalue);
> ..and later..
> ResultPolyData->Delete();
> }
>
> I suspect memory leaks using this procedure.
> - What is happening with the cF->GetOutput()? Is all the working data of cF
> really deleted?

no the shallow copy reference keeps the polydata's points for instance alive.

> - Is everything properly deleted at the end of the calling function?
> - What would be the proper manner?
> - Could a method from the vtkobject class solve the problem?
>
>
> Thanks for your help in advance.
>
> Greetings Hans
>
>
> _______________________________________________
> 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