# Roots and owners

Every memo and effect belongs to an owner. Disposing that owner runs its cleanups and disposes
its children. Disposing it again is safe.

The owner can be the graph's `Root`, a scope created by `createRoot`, or the current run of an
enclosing effect, owning memo or boundary.

## Create a scope

- `createRoot body` creates a scope, runs `body` with its `Owner`, and returns `body`'s result.
- `owner.Dispose ()` disposes everything created inside that scope.
- `graph.Dispose ()` disposes every node the graph owns. Use `use graph = new Graph ()` to dispose
  the graph automatically when the enclosing scope ends.

In this replay, disposing the root removes its effect's dependency. The signal remains available,
but later writes no longer run that effect.

<div class="partas-solid-card partas-solid-card--map">

<div class="partas-solid" data-partas-page="p05fe9e265f" data-partas-cell="c1"></div>

</div>

## Disposal

:::details Disposal order and nested roots

An owner runs its cleanups first, then disposes its children. Each group runs in reverse creation
order.

A root created inside an effect belongs to that effect's current run. It is disposed before the
effect's next run.
:::

:::warning Leaving a root or graph undisposed

A memo retains its source dependencies, and an effect keeps responding to changes, until its owner
is disposed. Dispose each `createRoot` owner when its work ends. Dispose the graph with
`use graph = new Graph ()` or `graph.Dispose ()`.
:::

Register subscriptions and other resources with [Cleanup](cleanup.md).
