[vtk-developers] Memory leak in vtkSmartPointer

Nasztanovics Ferenc naszta at naszta.hu
Tue Jun 22 23:12:50 EDT 2010


Hi,

In vtkSmartPointer we have the following code:

static T* CheckType(T* t) { return t; }
template <class U>
vtkSmartPointer& operator=(const vtkSmartPointer<U>& r)
  {
  this->vtkSmartPointerBase::operator=(CheckType(r.GetPointer()));
  return *this;
  }

void TakeReference(T* t)
  {
  *this = vtkSmartPointer<T>(t, NoReference());
  }

------------------

In my code I use 

vtkSmartPointer<vtkSomething> foo;
foo.TakeReference( vtkSomething::New() ); 

the reference count is 2. I tried the following code, too:

vtkSmartPointer<vtkSomething> foo;
foo = vtkSmartPointer<vtkSomething>::New() ); 

but the reference number is still 2.

Best regards,

Ferenc Nasztanovics


More information about the vtk-developers mailing list