[vtkusers] vtkSmartPointer usage question
Jeff Baumes
jeff.baumes at kitware.com
Fri Nov 6 08:53:47 EST 2009
>
> The only thing is not clear for me is how to force smartpointer to
> release the data.
>
>
Is this what you're looking for?
vtkSmartPointer<vtkType> sp = vtkSmartPointer<vtkType>::New();
...
sp = NULL; // Release would happen here.
This would decrement the reference count of the object by one. If no one
else holds a reference count of the object (i.e. reference count goes to
zero), it will be released from memory.
Normally you just wait for the smart pointer to go out of scope. If you
explicitly need to make the reference go away at a certain point, you might
as well not use smart pointers and just do this equivalent code:
vtkType* p = vtkType::New();
...
p->Delete();
Jeff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091106/5b695f21/attachment.htm>
More information about the vtkusers
mailing list