[IGSTK-Developers] Reference counting problem in igstkViewNew
Torleif Sandnes
torleif.sandnes at sintef.no
Tue Nov 13 08:46:34 EST 2007
Hi.
I have been debugging a memory leak in my application and come to the
conclusion that the bug probably is not in my code.
I load a volume and assign it to a member variable of my class. Then
I add it to igstk::ViewNew3D with RequestAddObject(). Internally, the
ViewNew3D class does the following:
In RequestAddObject():
m_ObjectToBeAdded = pointer;
This increases the reference count of the ObjectRepresentation by one.
In AddObjectProcessing():
m_Objects.push_back(m_ObjectToBeAdded);
stl will use operator= to create a copy of the smartpointer and the
reference count is increased by one.
In RequestRemoveObject():
m_ObjectToBeRemoved = pointer
operator= is called again and the reference count is now four!
Back to my code again:
I delete the class that holds the ObjectRepresentation and when my
smart pointer thus goes out of scope, the reference count is
decreased to three. And we are three reference counts away from
deleting the memory that the representation holds.
Do you agree that this is a bug?
Regards,
Torleif Sandnes
More information about the IGSTK-Developers
mailing list