By: T. Cargill
Published in: PLoPD2
Category: C++ Idioms
Summary: Management of dynamic object lifetimes in C++.
When a dynamic object is created in C++, the creator can determine the object's lifetime. If there is a narrow purpose for a dynamic object, let the creator control its lifetime. A narrow purpose does not imply that the object is short-lived or that the creator has exclusive access to it.
You're creating a dynamic object in C++ and can't use Creator as Sole Owner. Transfer ownership from the creator to another owner. Ownership may be transferred any number of times. This transfer must be an explicit part of the interface between the two. At any time, ownership rests with only one owner.
You're creating a dynamic object in C++ and can't use Creator as Sole Owner or Sequence of Owners. An object that defies simple characterization and management of its lifetime is likely to be long-lived. Allow arbitrary owners to declare unilateral interest in the dynamic object. The lifetime of the object continues until all the owners have relinquished their interest in it.