What disposes what
What disposes what in the Effects and lifecycle guide.
An owner is disposed when:
- you call the function returned by
render(),hydrate()orcreateRoot; - its parent is disposed (components, effects and memos are owners of what they create);
- a memo or effect that created it re-runs (everything created during the previous run is disposed first);
- control flow replaces it: a
ShoworSwitchbranch that is replaced, aFororIndexrow that leaves the list, anErrorBoundarythat switches to its fallback, aDynamicwhose component changes.
Disposal runs cleanups newest first, children before parents, and then the effects that depend on signals written by cleanups are flushed before the call returns (unless it happens inside a batch or a flush, whose own exit flushes).