[vtkusers] vtkDenseArray reference counting?

David Doria daviddoria+vtk at gmail.com
Mon Nov 16 11:56:15 EST 2009


>
> As your code is written now, you are telling the array to store raw
> pointers; it does not even know that the pointers are vtkObject
> subclasses, so it does not know it should increment the reference
> count. The correct way to make this "just work" is to define the
> storage container as
>
> vtkSmartPointer<vtkDenseArray<vtkSmartPointer<vtkRay> > > array = ...
>
> Of course you may need to do some trickery for allowing
> vtkSmartPointer<vtkRay> to be converted to a vtkVariant. Similarly, a
> nice way to store vtkObject classes in a std::vector (or any other STL
> storage container) is with:
>
> std::vector<vtkSmartPointer<vtkRay> > array;
> ...
> array[i] = vtkSmartPointer<vtkRay>::New();
>
> This will automatically keep a reference count for each object in the
> array until the array is destructed.
>
> Jeff
>

I had to add

#include "vtkVariant.h"

and

 operator vtkVariant() const { return vtkVariant(); }

to vtkSmartPointer.h

Jeff, is there anyway you can commit those changes so this will work for
everyone?

Thanks,

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


More information about the vtkusers mailing list