types.WeakRef.weakref
Method on every
weakrefweakref(): any
Returns a weak reference to this weakref.
Return value
A new weakref, distinct from this, whose ref() gives back this (the original weakref object) for as long as something else still holds a strong reference to it - not the value this itself points at.
Notes
A weakref object is reference counted, unlike the scalar types where this same method is a no-op; see types.Integer.weakref for that contrast and for the meaning of the shown receiver, (table|userdata|instance|class|null). That list does not restrict the valid types - the method accepts any of them, weakref included.
Example
let t = {}
let wr1 = t.weakref()
let wr2 = wr1.weakref() // weakref *is* reference counted, so this is a real one
println("type(wr2) =", type(wr2))
println("wr2.ref() == wr1 =", wr2.ref() == wr1)Output:
type(wr2) = weakref
wr2.ref() == wr1 = trueSee also
ref | Returns the value this weakref points at, or null once that value is gone. |
constructor | Returns a weak reference to obj. This is what runs when types.WeakRef itself is called, types.WeakRef(obj) - the same conversion obj.weakref() performs as a method. |
weakref | Returns the integer itself. |
| weakref | class index |