ComponentTreeRegistry

Thread-safe singleton registry that holds weak references to all ComponentTree instances that are still in memory, including released ones that have not been garbage collected yet.

Gated by enabled so it is zero-cost when disabled. The flag is set by com.facebook.litho.hotreload.LithoHotReloadHandler.install and by Litho Observability in debug and perf builds.

Types

Link copied to clipboard
class StateCounts(val attached: Int, val detached: Int, val released: Int)
Link copied to clipboard
class TreeInfo(val id: Int, val rootName: String, val isAttached: Boolean, val createdAtMs: Long, val releasedAtMs: Long?)

State of one registered tree.

Properties

Link copied to clipboard

Functions

Link copied to clipboard

Counts registered trees by state. Takes no ComponentTree lock, so it is cheap to sample.

Link copied to clipboard

Forces a re-resolve on every registered ComponentTree by setting a new root with a fresh component ID via Component.makeShallowCopyWithNewId. This causes every component's render() to be called again (picking up hot-swapped bytecode) while preserving hook state.

Link copied to clipboard
fun forEach(action: (ComponentTree) -> Unit)

Iterates over a snapshot of all unreleased ComponentTree instances.

Link copied to clipboard

Marks tree as released. The tree stays in the registry until it is garbage collected, so a released tree that is still reachable can be reported as a leak.

Link copied to clipboard

Adds tree to the registry if enabled is true.

Link copied to clipboard

Returns the state of every registered tree. Reads root names under each tree's lock, so use countByState for frequent sampling.