[vtkusers] Recreating a smart pointer object after deletion
David Doria
daviddoria at gmail.com
Tue Nov 23 12:46:12 EST 2010
> Just another quick comment: after calling Delete() on a smart pointer, any
> use of that smart pointer (including reassigning it) will cause a crash. I
> suspect even your second code block with vtkSmartPointer::New() will work if
> you remove the Delete().
>
> When you reassign a smart pointer, its previous contents are automatically
> freed.
>
> David
If I do this (which works fine (no crash)):
vtkSmartPointer<vtkFloatArray> distances =
vtkSmartPointer<vtkFloatArray>::New();
std::cout << distances->GetNumberOfComponents() << std::endl;
distances.TakeReference(vtkFloatArray::New());
std::cout << distances->GetNumberOfComponents() << std::endl;
there is a leak, right? The first vtkFloatArray object is never
deleted. How do you delete the memory allocated to the first object?
(This is why I had tried calling Delete(), which you say should never
be done (and I agree, as it causes a crash every time :) )
David D
More information about the vtkusers
mailing list