Quirrel4.41.0

types.Thread.weakref

Method on every thread
weakref(): 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

examples/types/thread/weakref.nut
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() = null

See also

getstatusReturns the thread's current state as a string.
weakrefReturns a weak reference to the table.
threadclass index