WeakRef is a smart pointer that holds a non-owning ("weak") reference to
an object that is managed by RefCounted. It must be converted to a
RefCounted via asRefCounted() in order to access the referenced object.
WeakRef models temporary ownership: when an object needs to be accessed
only if it exists, and it may be deleted at any time by someone else,
WeakRef is used to track the object, and it is converted to RefCounted
to assume temporary ownership. If the original RefCounted is destroyed at
this time, the object's lifetime is extended until the temporary
RefCounted is destroyed as well.
Another use for WeakRef is to break reference cycles formed by objects
managed by RefCounted. if such cycle is orphaned (i.e. there are no
outside shared pointers into the cycle), the RefCounted reference counts
cannot reach zero and the memory is leaked. To prevent this, one of the
pointers in the cycle can be made weak.
WeakRef is a smart pointer that holds a non-owning ("weak") reference to an object that is managed by RefCounted. It must be converted to a RefCounted via asRefCounted() in order to access the referenced object.
WeakRef models temporary ownership: when an object needs to be accessed only if it exists, and it may be deleted at any time by someone else, WeakRef is used to track the object, and it is converted to RefCounted to assume temporary ownership. If the original RefCounted is destroyed at this time, the object's lifetime is extended until the temporary RefCounted is destroyed as well.
Another use for WeakRef is to break reference cycles formed by objects managed by RefCounted. if such cycle is orphaned (i.e. there are no outside shared pointers into the cycle), the RefCounted reference counts cannot reach zero and the memory is leaked. To prevent this, one of the pointers in the cycle can be made weak.