[vtkusers] SmartPointer questions
David Doria
daviddoria+vtk at gmail.com
Thu Oct 22 15:57:51 EDT 2009
1) Smart pointers when not allocating memory (using New())
Given the below context, does it make sense to make polydata a smart
pointer? Or is the actual memory released when the reader goes out of
scope so a normal polydata pointer is the "right" thing to do?
vtkSmartPointer<vtkXMLPolyDataReader> reader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(InputFilename.c_str());
reader->Update();
//the question is which of these to use?
vtkPolyData* polydata = reader->GetOutput(); //normal pointer
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput(); //smart pointer
2) What happens if you accidentally do this:
vtkSmartPointer<vtkXMLPolyData> polydata = vtkPolyData::New();
(vtkSmartPointer<> is missing on the rvalue)
It seems to behave just like as if you had not used a smart pointer at
all - the object does not get automatically deleted when it goes out
of scope. So this is just assigning a normal pointer to a smart
pointer variable? Can that be caught to produce a warning/error? Or is
there any case in which you would want to do something like this? Is
this exactly the same thing that is going on in the first question?
Thanks,
David
More information about the vtkusers
mailing list