43 , _preDeleteCallbacks()
55 , _preDeleteCallbacks()
67 #if 0 // No exceptions in destructors. jhrg
69 "~RCObject() called with a non-empty listener list!");
77 BESDEBUG(
"ncml:memory",
"Ref count for " << printRCObject() <<
" is now: " << _count << endl);
88 const_cast<RCObject*
>(
this)->executeAndClearPreDeleteCallbacks();
91 BESDEBUG(
"ncml:memory",
"Releasing back to pool: Object ref count hit 0. " << printRCObject() <<
92 " with toString() == " <<
toString() << endl);
93 _pool->
release(const_cast<RCObject*>(
this));
97 BESDEBUG(
"ncml:memory",
"Calling delete: Object ref count hit 0. " << printRCObject() <<
98 " with toString() == " <<
toString() << endl);
104 BESDEBUG(
"ncml:memory",
"unref() called and: " << printRCObject() << endl);
122 _pool->
remove(const_cast<RCObject*>(
this));
130 return printRCObject();
134 RCObject::printRCObject()
const
136 std::ostringstream oss;
137 oss <<
"RCObject@(" <<
138 reinterpret_cast<const void*
>(
this) <<
139 ") _count=" << _count <<
140 " numberDeleteListeners=" << _preDeleteCallbacks.size();
151 _preDeleteCallbacks.begin(),
152 _preDeleteCallbacks.end(),
153 pCB) == _preDeleteCallbacks.end())
155 BESDEBUG(
"ncml:memory",
"Adding WeakRCPtr listener: " << printRCObject() <<
156 " is getting listener: " << reinterpret_cast<const void*>(pCB) << endl);
157 _preDeleteCallbacks.push_back(pCB);
158 BESDEBUG(
"ncml:memory",
"After listener add, obj is: " << printRCObject() << endl);
168 BESDEBUG(
"ncml:memory",
"Removing WeakRCPtr listener from: " << printRCObject() <<
169 " Removed listener: " << reinterpret_cast<const void*>(pCB) << endl);
170 _preDeleteCallbacks.remove(pCB);
171 BESDEBUG(
"ncml:mempory",
"Object after remove listener is: " << printRCObject() << endl);
176 RCObject::executeAndClearPreDeleteCallbacks()
183 while (! (_preDeleteCallbacks.empty()) )
186 _preDeleteCallbacks.pop_front();
212 RCObjectSet::const_iterator foundIt = _liveObjects.find(pObj);
213 return (foundIt != _liveObjects.end());
221 throw string(
"Internal Pool Error: Object added twice!");
223 _liveObjects.insert(pObj);
232 _liveObjects.erase(pObj);
239 BESDEBUG(
"ncml:memory",
"RCObjectPool::release(): Calling delete on released object=" <<
240 pObj->printRCObject() <<
246 BESDEBUG(
"ncml:memory",
"RCObjectPool::release(): Removing object, but not deleting it: "
247 << pObj->printRCObject()
253 BESDEBUG(
"ncml:memory",
"ERROR: RCObjectPool::release() called on object not in pool!! Ignoring!" << endl);
260 BESDEBUG(
"ncml:memory",
"RCObjectPool::deleteAllObjects() started...." << endl);
261 RCObjectSet::iterator endIt = _liveObjects.end();
262 RCObjectSet::iterator it = _liveObjects.begin();
263 for (; it != endIt; ++it)
269 pObj->executeAndClearPreDeleteCallbacks();
270 BESDEBUG(
"ncml:memory",
"Calling delete on RCObject=" << pObj->printRCObject() << endl);
274 _liveObjects.clear();
275 BESDEBUG(
"ncml:memory",
"RCObjectPool::deleteAllObjects() complete!" << endl);
virtual std::string toString() const
Just prints the count and address.
RCObjectPool()
Create an empty pool.
void addPreDeleteCB(UseCountHitZeroCB *pCB)
Add uniquely.
#define NCML_ASSERT(cond)
virtual int unref() const
Decrease the reference count by one.
void deleteAllObjects()
Call delete on all objects remaining in _liveObjects and clear it out.
A monitoring "pool" class for created RCObject's which allows us to forcibly delete any RCOBject's re...
Helper class for temporarily hijacking an existing dhi to load a DDX response for one particular file...
#define NCML_ASSERT_MSG(cond, msg)
RCObject(RCObjectPool *pool=0)
If the pool is given, the object will be released back to the pool when its count hits 0...
void remove(RCObject *pObj)
Remove the object from the pool, but don't delete it.
void removePreDeleteCB(UseCountHitZeroCB *pCB)
Remove it exists.
virtual int ref() const
Increase the reference count by one.
void release(RCObject *pObj, bool shouldDelete=true)
Tell the pool that the object's count is 0 and it can be released to be deleted or potentially reused...
A base class for a simple reference counted object.
Interface for registering callbacks to the RCObject for when the usecount hits 0 but before the deall...
bool contains(RCObject *pObj) const
virtual ~RCObjectPool()
Forcibly delete all remaining objects in pool, regardless of ref count.
virtual int getRefCount() const
Get the current reference count.
virtual void executeUseCountHitZeroCB(RCObject *pAboutToDie)=0
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
void add(RCObject *pObj)
Add the object to the pool uniquely.
Interface class for a reference counted object.
virtual void removeFromPool() const
If the object is in an auto-delete pool, remove it from the pool and force it to only delete when it'...