Quirrel4.41.0

types.Array.weakref

Method on every array
weakref(): any

Returns a weak reference to this array.

Return value

A new weakref value. It does not keep the array alive; once nothing else references the array, the weak reference stops resolving.

Notes

Call ref on the result to get the array back.

Example

examples/types/array/weakref.nut
let a = [1, 2, 3];
let w = a.weakref();
println("type(w) =", type(w));
println("w.ref() == a:", w.ref() == a);   // ref() gets the original array back
println("w.ref().len() =", w.ref().len());
Output:
type(w) = weakref
w.ref() == a: true
w.ref().len() = 3

See also

refReturns the value this weakref points at, or null once that value is gone.
is_frozenReports whether this array reference is frozen.
arrayclass index