deleteAll method

void deleteAll({
  1. bool force = false,
})

Deletes the dependency registered under key on behalf of a disposed route, keeping it alive when still-mounted widgets depend on it.

Meant for internal usage of GetDependencyScope: when a scope is disposed, the instances linked to it are deleted. An instance that still has widget subscribers (GetBuilder/GetX listeners) at that moment may be shared with widgets of another, still-visible route — e.g. a controller created during a rebuild of a lower route's subtree while the disposed route was topmost — so its deletion is deferred to the end of the frame, after the disposed route's own subtree has unmounted and released its subscriptions:

  • if no subscriber remains, the instance is deleted normally;
  • if subscribers remain, they belong to still-mounted widgets of other routes and the instance is kept alive (it is disposed later by its creator widget's unmount or an explicit delete).

A registration superseded while the route was disposing (pending lateRemove chain) is peeled synchronously, exactly like delete. Deletes all registered instances from memory, invokes their onDelete/close lifecycles, and cleans up resources.

  • force If true, deletes even the instances marked as permanent.

Implementation

/// Deletes all registered instances from memory, invokes their onDelete/close lifecycles,
/// and cleans up resources.
///
/// - [force] If true, deletes even the instances marked as `permanent`.
void deleteAll({bool force = false}) {
  final keys = factories.keys.toList();
  for (final key in keys) {
    delete(key: key, force: force);
  }
}