Using RWTCountedPointer
RWTCountedPointer is a smart pointer template class that acts as a handle to a reference-counting body. Each time an instance of this class is bound to a body instance, it increments the reference-count maintained by that body. Each time an instance of this class detaches from a body instance, it decrements the body's reference-count and, if there are no more references, deletes the body instance. The reference-counting relieves clients of the burden of tracking whether it is safe to delete a body instance.
The class specified as the
Body parameter to
RWTCountedPointer must provide:
A member function for incrementing the reference-count, declared as
void addReference() A member function for decrementing the reference-count, declared as
unsigned removeReference() The Body has the responsibility to maintain the reference-count, usually by containing an attribute member of type unsigned.