Class WeakRef<T>

#include <Geode/utils/cocos.hpp>
template<class T>classWeakRef{ ... }

A smart pointer to a managed CCObject-deriving class. Like Ref, except only holds a weak reference to the targeted object. When all non-weak references (Refs, manual retain() calls) to the object are dropped, so are all weak references.

In essence, WeakRef is like a raw pointer, except that you can know if the pointer is still valid or not, as WeakRef::lock() returns nullptr if the pointed-to-object has already been freed.

Note that an object pointed to by WeakRef is only released once some WeakRef pointing to it checks for it after all other references to the object have been dropped. If you store WeakRefs in a global map, you may want to periodically lock all of them to make sure any memory that should be freed is freed.

Template parameters

T

A type that inherits from CCObject.
Examples0
Public static methods0
Public member functions14
geode::Ref<T>lock()const

Lock the WeakRef, returning a Ref if the pointed object is valid or a null Ref if the object has been freed

boolvalid()const

Check if the WeakRef points to a valid object

voidswap(
T*other
)

Swap the managed object with another object. The managed object will be released, and the new object retained

Parameters

other

The new object to swap to
geode::Ref<T>operator=(
T*obj
)
No description provided
geode::WeakRef<T>&operator=(
geode::WeakRef<T>const&other
)
No description provided
geode::WeakRef<T>&operator=()
No description provided
booloperator==(
T*other
)
const
No description provided
booloperator==(
geode::WeakRef<T>const&other
)
const
No description provided
booloperator!=(
T*other
)
const
No description provided
booloperator!=(
geode::WeakRef<T>const&other
)
const
No description provided
booloperator<(
geode::WeakRef<T>const&other
)
const
No description provided
booloperator<=(
geode::WeakRef<T>const&other
)
const
No description provided
booloperator>(
geode::WeakRef<T>const&other
)
const
No description provided
booloperator>=(
geode::WeakRef<T>const&other
)
const
No description provided
Fields0
Protected member functions0
Protected fields0