Explanation: The purpose of
this plate is to explain the memory management strategy employed
within the Archon X3D Engine. The so-called
"smart-pointer"
is the central concept here, and all references shown above are in
fact smart-pointers. Simply stated, the time of destruction of an
object is determined as the time when the last smart-pointer to it is
destroyed. The concept of smart-pointers is further explained
here.
Cycles within the reference graph could not be avoided in the
case of the Archon X3D Engine. This was a problem, since such cycles
normally lead to memory leak. As a solution we came up with the
concept of
"forward"
vs. "backward" references. The idea here is to maintain two
individual reference counters in each object. One for each of the two
types of references. The object gets destroyed when both counters
reach zero. But, that alone does not solve anything. The new concept
is that we generate an event in the object when the forward counter
reaches zero. It then becomes the responsibility of the object to
handle this event by taking appropriate actions to ensure that all
backwards references to itself will be destroyed within the near
future. This normally reduces to nullifying private forward references
to other objects. The concept of forward and backward references is
further explained
here.
With these concepts in place, what one should be looking out for in
the graph above is loops within one type of references (blue or
black). Such loops are indeed illegal and would lead to memory leak.
With the exception of transient references (explained later) all
forward references within the Archon X3D Engine are used to establish
containment relations. Further more the objects in the graph above are
arranged such that all forward references (solid black) lead downwards
indicating that objects in general are children of the objects
appearing above them.
Backwards references (blue), on the other hand, never represent a
containment relation. Within the Archon X3D Engine they are always
added as a means for one object to access some other object. Often the
referring object will be a child of the referenced object, but it need
not be so. Note that while forward references always lead upwards in
the graph, backwards references always lead downwards.
Transient references are forwards references used for purposes that
are more short-termed than that of establishing containment
relations. An example from the graph above is the reference drawn from
the session object of "Session 1" to a node in "Application 1". The
presence of this reference denotes the fact that the session contains
an inbound event queue which sometimes contain events targeted at
nodes in the scene graph.
Transient references are used extensively throughout the Archon X3D
Engine, many of them simply being objects on the stack. As can be seen,
only a few of them are indicated in the graph above - there are simply
too many to indicate them all. Fortunately, since they are transient,
the loops that they might introduce are themselves transient and thus
will not cause memory to leak.