[vtk-developers] Memory leak in vtkSmartPointer
Nasztanovics Ferenc
naszta at naszta.hu
Thu Jun 24 04:18:48 EDT 2010
Hi,
I debugged the following code (Is it a correct use case?):
vtkSmartPointer<vtkSomething> foo;
foo.TakeReference( vtkSomething::New() );
When TakeReference run:
1) vtkSomething::New() - reference number grow (1)
2) TakeReference call: vtkSmartPointer<T>(t, NoReference()); - constructor, no reference count growing (1)
3) TakeReference call: vtkSmartPointerBase::operator=(CheckType(r.GetPointer())); - reference number grow (2)
when I leave the block UnRegister(NULL) called just once -> this instance of vtkSomething object has left in memory.
I debugged the following code, too (Is it a correct use case?):
vtkSmartPointer<vtkSomething> foo;
foo = vtkSmartPointer<vtkSomething>::New() );
1) vtkSmartPointer<T>(T::New(), NoReference()); - reference count grow (1)
2) vtkSmartPointerBase::operator=(CheckType(r.GetPointer())); - reference number grow (2)
when I leave the block UnRegister(NULL) called just once -> this instance of vtkSomething object has left in memory.
Platform: Linux,
CPU: G5 PowerPC
GCC: 4.3.2
Best regards,
Ferenc Nasztanovics
________________________________________
Feladó: vtk-developers-bounces at vtk.org [vtk-developers-bounces at vtk.org], meghatalmazó: Nasztanovics Ferenc [naszta at naszta.hu]
Küldve: 2010. június 23. 12:12
Címzett: vtk-developers at vtk.org
Tárgy: [vtk-developers] Memory leak in vtkSmartPointer
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
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtk-developers
More information about the vtk-developers
mailing list