Avoiding Floating Reference Cycles

To avoid floating reference cycles, Server lets you define sophisticated relations among objects. To support these relations, Server internally manipulates smart pointers which offer more elaborate semantics than ordinary pointers.

Avoiding Floating Reference Cycles

Floating reference cycles are avoided, provided that you respect the rules listed below:

  1. Use Server relations instead of smart pointers to establish relations among objects.

  2. Use the static member function IlsModel::SetIntegrityChecked—at least during the development phase—to make sure that ownership relations do not produce cycles. By default, when an ownership relation is broken, if the target of this relation is also the target of a use relation, then the use relation will be broken as well.

  3. Rely on use- and ownership-relation default behavior to avoid a situation in which an object of type IlsObject that is not owned is the target of a use relation.

  4. Hold a smart pointer to each entity by storing these entities in a dictionary.

Demonstration

Let us suppose that a reference cycle is generated:

  • Rule 1 ensures that the cycle is composed of relations only.

  • Rule 2 ensures that at least one of the relations is a use relation.

  • Rule 3 ensures that the target of the relation is an entity.

  • Rule 4 ensures that at least one additional smart pointer points to this entity: the smart pointer stored in the dictionary. The cycle is not floating.