PreviousNext

Reference Counting: How Objects Keep Track of Multiple Clients

Reference counting is simply a record that each dynamic object maintains internally of how many clients have a reference to it. Dynamic object reference counting on a server is handled for you by DCE. Reference counting is maintained so that a server knows when to finally release the resources of an object. An object's reference count increases when the client passes a dynamic object to another application, and an object's reference count decreases when each object reference is deleted. This is why we have stressed that it is the responsibility of clients to delete their object references.

In addition, if one client passes a dynamic object to another and the original client then exits or dies, the second client's object is perfectly valid with respect to the server.

With the volatility of a distributed environment, even well-designed clients could lose a connection or exit unexpectedly, leaving the reference count in an incorrect state. Robust servers can delete any dynamic objects they wish, but they run the risk of causing an unexpected failure on clients. Depending on the application, this may be acceptable. For example, in a trading system where dynamic objects may be valid only during a single day, nightly purging of stale objects makes sense.