[vtkusers] vtkDenseArray reference counting?

David Doria daviddoria+vtk at gmail.com
Fri Nov 13 14:05:18 EST 2009


If I create a vtkDenseArray of pointers, then create a smart pointer to an
object, store it in the dense array, then let the smart pointer go out of
scope, shouldn't it know that it is still needed in the dense array so it
should not delete the memory? I looked at the reference count and it does
not increase when the object is added to the array with SetValue.

Here is what I was trying to do:

 vtkSmartPointer<vtkDenseArray<vtkRay*> > array =
vtkSmartPointer<vtkDenseArray<vtkRay*> >::New();
 array->Resize(5,1);

 for(unsigned int i = 0; i < 5; i++)
 {
   vtkSmartPointer<vtkRay> Ray = vtkSmartPointer<vtkRay>::New();
   double origin[3] = {0.0, 0.0, 0.0};
   double direction[3] = {1.0, 0.0, 0.0};
   Ray->SetOrigin(origin);
   Ray->SetDirection(direction);
*//reference count of Ray here is 1*
   array->SetValue(i, 0, Ray);
*//reference count of array->GetValue(i,0) here is 1*
   vtkRay* RetrievedRay = array->GetValue(i,0);
   vtkstd::cout << *(RetrievedRay) << vtkstd::endl;
 }

 for(unsigned int i = 0; i < 5; i++)
 {
   vtkRay* RetrievedRay = array->GetValue(i,0);
   vtkstd::cout << *(RetrievedRay) << vtkstd::endl;* //segfault occurs here*
 }

Is vtkDenseArray not designed to be used like this?

Thanks,

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091113/87bf0f9f/attachment.htm>


More information about the vtkusers mailing list