Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Drop order

Rune distinguishes between places (such as variables or fields that hold a reference) and values (the underlying data).

Because non-primitive values are reference counted, multiple places can point to the same value:

let a = 42;
let b = a;

Here, b is a distinct place holding a value. For reference-counted values, there are two ways a value can be dropped:

  • All places referencing it go out of scope.
  • The value is explicitly dropped with drop(value).

Explicitly calling drop frees the value immediately. Attempting to read or write through any remaining place that still points to it produces a runtime error.

Variables

A variable declaration defines a place:

let var = 42;

When a variable goes out of scope, its place is dropped. The underlying value is only dropped if that was the last place referencing it:

let object = {
    let var = 42;
    #{ var }
};

// `object` can still be used here and `var` is still live.

Temporaries

Temporary values are created when evaluating expressions such as:

let var = [42, (), "hello"];

The exact drop order for temporaries is not strictly specified and their lifetime may be extended, but never past the end of the block in which they are created.