13.2.1 How it works
A value is alive if it can be reached from a variable of some active frame. When it no longer can, its memory may be recovered. The program cannot observe when or whether that happens: there are no finalizers, no weak references and no free-memory queries.
The active frames point to an object, which points to another. A third object has no arrow reaching it and is marked as unreachable.
The proof that it is unobservable is strong: running a program collecting on every value creation, or never collecting, gives exactly the same output, termination and trace.
A value reachable only from variables whose block has ended —a loop body, a branch— stops counting towards the cell limit as soon as that block ends.
ProgramObjects created and forgotten
Class Caja
Define valor As Integer;
EndClass
Algorithm Basura
Define total As Integer <- 0;
For i <- 1 To 1000 Do
Define c As Caja <- New Caja();
c.valor <- i;
total <- total + c.valor;
EndFor
Write total;
EndAlgorithmOutput
500500
The program finishes normally.
Every round creates a box that stops being reachable when the round ends. Suspended tasks are roots too: what their frames hold, their pending results and the channels' messages stay alive as long as needed.
In short
- Values created while running live on the heap.
- What cannot be reached is recovered, with no observable effect.
- Collecting always or never gives the same run.