dispose method

void dispose()

Stops observing, stops listening for identity changes, and restores the previous observer if the slot is still ours.

Everything recorded, requests included, is dropped: a disposed inspector is not told when the identity changes, so anything it kept would outlive the principal it belongs to. Every read after this returns empty. The controls are released, not aborted: the principal is unchanged, so a request waiting out simulated latency is sent and the transport passes through from then on. A request a principal change already orphaned stays aborted. The controls' connectivity stream is then closed, after the release has reported the network back.

Implementation

void dispose() {
  if (_disposed) return;
  _disposed = true;
  _stopWatching();
  _stopSettled();
  if (identical(cache.observer, _observer)) cache.observer = _previous;

  _log.clear();
  _ring?.clear();
  requestLog?.clear();
  _outbox.clear();
  _sync.clear();
  // Released, then disposed, so a simulator nothing will ever switch again
  // holds no listeners: the cache keeps it as its transport, passing
  // through.
  final controls = this.controls;
  if (controls != null) {
    controls.release();
    unawaited(controls.dispose());
  }
  _fetching.clear();
  _seen.clear();
  _pending.clear();
  _cause = null;
  // Inside a change window the queue is already empty, and nothing should
  // reach a subscriber from here.
  _log.release(deliver: false);
  _changing = false;
}