On this page:
Weak  Box
Weak  Box
Weak  Box.value
Ephemeron
Ephemeron
Ephemeron.value
0.45+9.1

7.11 Weak References🔗ℹ

A weak box is an object with a single value field, which can be accessed from a box wb as wb.value, but wb.value can asynchronously change to #false if the memory manager determines that the value is not otherwise reachable.

An ephemeron is similarly an object with a value field, but also a key, where both a key and value are supplied when the ephemeron is constructed. The value in an ephemeron eph can be accessed as eph.value, but eph.value can asynchronously change to #false if the memory manager determines that the key (as opposed to the value) is not otherwise reachable. Crucially, an ephemeron’s reference to a key does not keep the key reachable, even if that key is reachable via the ephemeron’s value; that is, the key and value can be simultaneously determined to be unreachable.

A WeakMutableMap or WeakMutableSet retains elements weakly in the same sense as a weak box.

annotation

WeakBox

 

function

fun WeakBox(val :: Any) :: WeakBox

 

property

property (wb :: WeakBox).value :: Any

The WeakBox annotation matches any weak box.

The WeakBox constructor creates a weak box whose initial value is val, but which can be replaced by the memory manager at any time by #false if val becomes otherwise unreachable.

The WeakBox.value property accesses the current value from a weak box.

annotation

Ephemeron

 

function

fun Ephemeron(key :: Any, val :: Any) :: Ephemeron

 

property

property (eph :: Ephemeron).value :: Any

The Ephemeron annotation matches any ephemeron.

The Ephemeron constructor creates an ephemeron initially referencing the given key value is val. The memory manager can replace the ephemeron’s val any time by #false if key becomes otherwise unreachable, but the ephemeron’s own reference to key (directly or via val) does not make the key reachable.

The Ephemeron.value property accesses the current value from an ephemeron.