Handles and ownership
How Waft keeps Flutter's objects in an arena, and how a Ref keeps one alive.
Dart's objects point at each other freely; Rust's cannot. Waft keeps every Flutter object — each element, state, render object, controller, focus node and route — in the App's arena, and names it there by a Handle<T>, which is Copy and holds nothing. app.get(handle) reads the object, and app.get_mut(handle) changes it. Exclusivity lasts one field access, never a whole pass.
What keeps an object
A Ref<T> keeps an object alive: it is Dart's ordinary reference. It derefs to its Handle<T>, so every method of the handle is callable on it, and its clones share one count. When the last Ref to an object is dropped, the object is freed at the next checkpoint, the end of the current event, so a bare Handle stays good until then.
app.create(value)puts a value in the arena and answers the oneRefthat keeps it; Waft's constructors answer one, asTextEditingController::new(app)andFocusNode::new(app)do.- A field, a widget, or a closure that is stored holds a
Ref. Code that only uses an object during a call takes the bareHandle. handle.keep(app)answers a newRefto an object something else keeps;handle.upgrade(app)answersNonewhere nothing does. There is noRef::new.- An object with a
dispose, such as a controller or a focus node, is disposed of by whoever made it, in itsState'sdispose; a debug build reports one freed without it.
Erased handles
A field Dart types as a base class, such as a TextBox's controller or the Navigator's routes, holds an erased handle, which names any object of that kind: AnyTextEditingController, AnyFocusNode, AnyRoute. A Ref becomes the kept one with into_erased(), which hands over its count, or erase(), which shares it:
let controller = TextEditingController::new(app);
TextBox::new(controller.erase()); // a TextEditingControllerRef
let route = PageRouteBuilder::new(app, page);
Navigator::push(app, context, route.into_erased()); // a RouteRefThe names of the kept ones end in Ref: TextEditingControllerRef, FocusNodeRef, RouteRef, each a Retained of the erased handle, as Ref<T> is a Retained<Handle<T>>.
A handle's own
as_controller(),as_node()oras_route()answers the bare erased handle, which keeps nothing; a widget asks for the kept one, so useerase()orinto_erased().
Entities are not in the arena
An Entity<T> is a counted handle of its own kind, made by app.new_entity: its object lives while an Entity to it does, reading it in build subscribes the widget, and notify rebuilds what read it. That is what the app's logic wants, and what an arena object does not do (State).