Quirrel4.41.0

types.Instance.weakref

Method on every instance
weakref(): any

Returns a weak reference to the instance.

Return value

A weakref value. Its ref() method gives back this same instance as long as something else still keeps it alive, or null once it has been collected.

Notes

Holding a weak reference to an instance does not keep it, or the class it points back to through getclass(), alive.

Example

examples/types/instance/weakref.nut
class Foo { x = 1 }
let inst = Foo()
let wr = inst.weakref()
println("wr.ref() == inst =", wr.ref() == inst)
Output:
wr.ref() == inst = true

See also

weakrefReturns a weak reference to the class.
refReturns the value this weakref points at, or null once that value is gone.
instanceclass index