[vtkusers] vtkSmartPointer usage question

Michael Jackson mike.jackson at bluequartz.net
Thu Nov 5 08:18:32 EST 2009


case b.
--
Mike Jackson <www.bluequartz.net>

On Nov 4, 2009, at 8:17 PM, Alex Malyushytskyy wrote:

> 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
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list