types.Instance.weakref
Method on every
instanceweakref(): 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
class Foo { x = 1 }
let inst = Foo()
let wr = inst.weakref()
println("wr.ref() == inst =", wr.ref() == inst)Output:
wr.ref() == inst = trueSee also
weakref | Returns a weak reference to the class. |
ref | Returns the value this weakref points at, or null once that value is gone. |
| instance | class index |