AngelScript
|
Path: /sdk/add_on/weakref/
The weakref
type is a template type for holding weak references to objects, i.e. the references that will not keep the referred object alive.
The type is registered with RegisterScriptWeakRef(asIScriptEngine*)
.
In the scripts it can be used as follows:
class MyClass {} MyClass @obj1 = MyClass();
// Keep a weakref to the object weakref<MyClass> r1(obj1);
// Keep a weakref to a readonly object const_weakref<MyClass> r2(obj1);
// As long as there is a strong reference to the object, // the weakref will be able to return a handle to the object MyClass @obj2 = r1.get(); assert( obj2 !is null );
// After all strong references are removed the // weakref will only return null @obj1 = null; @obj2 = null;
const MyClass @obj3 = r2.get(); assert( obj3 is null );