types.Thread.weakref
Method on every
threadweakref(): any
Returns a weak reference to the thread.
Return value
A weakref value. Calling its ref() method gives the thread back for as long as something else still holds a strong reference to it; once the thread's refcount drops to zero, ref() returns null instead.
Notes
Takes no arguments. A suspended thread's own stack keeps its local variables alive independently of this; dropping every strong reference to a suspended thread while nothing ever wakes it up again lets the thread itself, and everything only it still referenced, be collected.
Example
function body() { suspend() }
local t = newthread(body)
let w = t.weakref()
println("typeof w, (w.ref() == t) =", typeof w, w.ref() == t)
t = null
println("w.ref() =", w.ref())Output:
typeof w, (w.ref() == t) = weakref true
w.ref() = nullSee also
getstatus | Returns the thread's current state as a string. |
weakref | Returns a weak reference to the table. |
| thread | class index |