[vtkusers] Deleting unknown object
Bill Lorensen
bill.lorensen at gmail.com
Sun Oct 18 13:00:08 EDT 2009
I recommend using vtkSmartPointer when creating vtk objects. This
relieves the user from worrying about leaks they may be causing. Of
course, there could still be internal leaks in objects, but those
should be considered bugs and reported appropriately.
Bill
On Sun, Oct 18, 2009 at 12:23 PM, David Doria <daviddoria+vtk at gmail.com> wrote:
> 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
> _______________________________________________
> 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