[vtkusers] vtkSmartPointer usage question

Alex Malyushytskyy alexmalvtk at gmail.com
Wed Nov 4 20:17:52 EST 2009


Assume I have the following pseudo-code ( :

vtkSmartPointer <Class> sptr = vtkSmartPointer <Class>::New();
....................
// case a
Class* p1 = Class::New();

// case b
vtkSmartPointer <Class> sptr2 = vtkSmartPointer <Class>::New();
............................

What is the correct way to associate smart pointer with
a) newly allocated pointer to the Class,
b) pointer another smart pointer points to

so currently associated  data is properly released and memory deallocated?
It looks like simple assigning does not work .

for the case 'a' I thought that
    sptr->Take(p1)
should work, but it seems in may case previously associated data is
not destroyed (destructor is not called), so I assume it is not
dereferenced for some reason.

for the case 'b'  my assumptions was that simple assigning should work:

sptr = sptr2;


Thanks in advance,
            Alex



More information about the vtkusers mailing list