Added a Referenced::unref_nodelete() method which unreferences but does
not delete the object even if its count goes to 0 or below. This should only be called in special circumstances, the ReaderWriter::ReadResult being one of them. This new method has allowed the problem of objects being multiple referenced on return from readNodeFile() & readImageFile().
This commit is contained in:
@@ -22,11 +22,21 @@ class SG_EXPORT Referenced
|
||||
/** increment the reference count by one, indicating that
|
||||
this object has another pointer which is referencing it.*/
|
||||
inline void ref() const { ++_refCount; }
|
||||
|
||||
/** decrement the reference count by one, indicating that
|
||||
a pointer to this object is referencing it. If the
|
||||
reference count goes to zero, it is assumed that this object
|
||||
is no longer referenced and is automatically deleted.*/
|
||||
inline void unref() const { --_refCount; if (_refCount<=0) delete this; }
|
||||
|
||||
/** decrement the reference count by one, indicating that
|
||||
a pointer to this object is referencing it. However, do
|
||||
not delete it, even if ref count goes to 0. Warning, unref_nodelete()
|
||||
should only be called if the user knows exactly who will
|
||||
be resonsible for, one should prefer unref() over unref_nodelete()
|
||||
as the later can lead to memory leaks.*/
|
||||
inline void unref_nodelete() const { --_refCount; }
|
||||
|
||||
/** return the number pointers currently referencing this object. */
|
||||
inline const int referenceCount() const { return _refCount; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user