Inherits Object, and Reference.
List of all members.
WeakReferences are necessary when building Object graphs to avoid leaking the Object graph due to cyclical references.
WeakReferences provide getter methods to safely obtain a normal Handle to the weakly referenced Object if it still exists. Once the Object becomes only weakly referenced its associated WeakReference will be automatically NULL'd out so that the Object may be reclaimed.
Consider a simple case of an Object tree, where parent's reference their children, and children reference their parents. With normal reference counting handles, the tree would be leaked even once all external references to the tree have been dropped. To resolve this issue the tree could be constructed such that parents reference their children via normal Handles, but children reference their parents via WeakReferences. This way as long as the parent is externaly refrenced its entire sub-tree will be retained. Once all external Handles to the parent are dropped the entire tree will be reclaimed as only WeakReferences would hold it together.
Similar to MemberHandles, WeakReferences tranfer their constness to their referenced Object. That is if a View to a WeakReference is held then only the View to the referenced Object will be available.
Do to the need to call the get() which returns an Object::View or Handle and then perform a cast, WeakReferences are somewhat cumbersome to make use of. WeakHandle and WeakView are TypedHandle like wrappers for WeakReference which makes using WeakReferences much simpler. In most cases these should be used rather than direct use of WeakReferences.
|WeakReference Handle definition. |
|WeakReference View definition. |
|WeakReference Holder definition. |
Public Member Functions
|virtual Object::Holder||get () const =0|
|Return a Holder, containing a View to the referenced Object. |
|virtual Object::Holder||get ()=0|
|Return a Holder to the referenced Object. |
|virtual Object::Holder get||(||)|| const
|virtual Object::Holder get||(||)||