[vtkusers] Deleting unknown object

David Doria daviddoria+vtk at gmail.com
Sun Oct 18 12:23:22 EDT 2009


On Wed, Oct 14, 2009 at 8:01 AM, Paul Edwards <paul.m.edwards at gmail.com> wrote:
> You do need to call Delete on everything that you create with New.
>
>>   vtkTree* MinimumSpanningTree = vtkTree::New();
>>   MinimumSpanningTree = MinimumSpanningTreeFilter->GetOutput();
>
> The problem you have here is you are setting the pointer value to the
> output of the filter.  When you call Delete at the end, it is not the
> memory that you obtained from calling New.  You should call one of the
> copy functions, e.g.
>
>    MinimumSpanningTree->ShallowCopy(MinimumSpanningTreeFilter->GetOutput());
>
> Regards,
> Paul
>

I see. So you can make a local pointer variable that points to the
data that is still in the filter without ever assigning new memory
like this:
vtkTree* MST = MinimumSpanningTreeFilter->GetOutput();

The problem with this is that if you delete the filter, MST now points
to invalid memory. In this case we must NOT delete MST. Is this
understanding correct?

Thanks,

David



More information about the vtkusers mailing list