The reference counting object

A reference counting object is one which uses reference counting to track concurrent references to itself and which arranges for automatic destruction of itself when the final reference is removed. It is also an object which can be named.

A reference counting object is any object which has CObject as its base class.

Constructing a CObject derived type, or calling its CObject::Open() member function, adds a reference to that object by adding one to its reference count. Calling its CObject::Close() member function removes a reference by subtracting one from its reference count. When the last user of the object calls CObject::Close(), the reference count becomes zero and the object is automatically destroyed.

The following drawing shows the idea.

A CObject is always part of a class hierarchy. It is a base class; an explicit CObject type is never instantiated.

The server side implementation of a client/server subsession uses a CObject.

See also: