AngelScript
weakref
Note
weakref is only available in the scripts if the application registers the support for it.

An object handle will keep the object it refers to alive as long as the handle itself exists. A weakref object can be used in place of the handle where the reference to the object is needed but the object shouldn't be kept alive.

  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 );

Supporting weakref object

Operators

  • @= handle assignment
  • is, !is identity operator
  • cast<type> cast operator

Methods

  • T@ get() const