The ReusableContentHost introduces the concept of reusing (or recycling) nodes, as well as deactivating parts of composition, while keeping the nodes around to reuse common structures in the next iteration. In this state, RememberObserver is not sufficient to track lifetime of data associated with reused node, as deactivated or reused parts of composition is disposed.
These callbacks track intermediate states of the node in reusable groups for managing data contained inside reusable nodes or associated with them (e.g. subcomposition).
Important: the runtime only supports node implementation of this interface.
Invoked when the group containing the node was deactivated. This happens when the content of ReusableContentHost is deactivated.
The node will not be reused in this recompose cycle, but might be reused or released in the future. Consumers might use this callback to release expensive resources or stop continuous process that was dependent on the node being used in composition.
If the node is reused, onReuse will be called again to prepare the node for reuse. Similarly, onRelease will indicate that deactivated node will never be reused again.
Invoked when the node was reused in the composition. Consumers might use this callback to reset data associated with the previous content, as it is no longer valid.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-05-15 UTC.
[null,null,["Last updated 2025-05-15 UTC."],[],[],null,["# ComposeNodeLifecycleCallback\n============================\n\nArtifact: [androidx.compose.runtime:runtime](/jetpack/androidx/releases/compose-runtime) \n[View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/ComposeNodeLifecycleCallback.kt+class:androidx.compose.runtime.ComposeNodeLifecycleCallback) \nAdded in [1.4.0](/jetpack/androidx/releases/compose-runtime#1.4.0)\nCommon/AllAndroid/JVMNative/C/iOSJavaScript\n - Cmn \n\n ```\n interface ComposeNodeLifecycleCallback\n ```\n\n*** ** * ** ***\n\nObserves lifecycle of the node emitted with [ReusableComposeNode](/reference/kotlin/androidx/compose/runtime/package-summary#ReusableComposeNode(kotlin.Function0,kotlin.Function1)) or [ComposeNode](/reference/kotlin/androidx/compose/runtime/package-summary#ComposeNode(kotlin.Function0,kotlin.Function1)) inside [ReusableContentHost](/reference/kotlin/androidx/compose/runtime/package-summary#ReusableContentHost(kotlin.Boolean,kotlin.Function0)) and [ReusableContent](/reference/kotlin/androidx/compose/runtime/package-summary#ReusableContent(kotlin.Any,kotlin.Function0)).\n\nThe [ReusableContentHost](/reference/kotlin/androidx/compose/runtime/package-summary#ReusableContentHost(kotlin.Boolean,kotlin.Function0)) introduces the concept of reusing (or recycling) nodes, as well as deactivating parts of composition, while keeping the nodes around to reuse common structures in the next iteration. In this state, [RememberObserver](/reference/kotlin/androidx/compose/runtime/RememberObserver) is not sufficient to track lifetime of data associated with reused node, as deactivated or reused parts of composition is disposed.\n\nThese callbacks track intermediate states of the node in reusable groups for managing data contained inside reusable nodes or associated with them (e.g. subcomposition).\n\nImportant: the runtime only supports node implementation of this interface.\n\nSummary\n-------\n\n| ### Public functions |\n|-------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|\n| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [onDeactivate](/reference/kotlin/androidx/compose/runtime/ComposeNodeLifecycleCallback#onDeactivate())`()` Invoked when the group containing the node was deactivated. | Cmn |\n| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [onRelease](/reference/kotlin/androidx/compose/runtime/ComposeNodeLifecycleCallback#onRelease())`()` Invoked when the node exits the composition entirely and won't be reused again. | Cmn |\n| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [onReuse](/reference/kotlin/androidx/compose/runtime/ComposeNodeLifecycleCallback#onReuse())`()` Invoked when the node was reused in the composition. | Cmn |\n\nPublic functions\n----------------\n\n### onDeactivate\n\nCmn \nAdded in [1.4.0](/jetpack/androidx/releases/compose-runtime#1.4.0) \n\n```\nfun onDeactivate(): Unit\n```\n\nInvoked when the group containing the node was deactivated. This happens when the content of [ReusableContentHost](/reference/kotlin/androidx/compose/runtime/package-summary#ReusableContentHost(kotlin.Boolean,kotlin.Function0)) is deactivated.\n\nThe node will not be reused in this recompose cycle, but might be reused or released in the future. Consumers might use this callback to release expensive resources or stop continuous process that was dependent on the node being used in composition.\n\nIf the node is reused, [onReuse](/reference/kotlin/androidx/compose/runtime/ComposeNodeLifecycleCallback#onReuse()) will be called again to prepare the node for reuse. Similarly, [onRelease](/reference/kotlin/androidx/compose/runtime/ComposeNodeLifecycleCallback#onRelease()) will indicate that deactivated node will never be reused again. \n\n### onRelease\n\nCmn \nAdded in [1.4.0](/jetpack/androidx/releases/compose-runtime#1.4.0) \n\n```\nfun onRelease(): Unit\n```\n\nInvoked when the node exits the composition entirely and won't be reused again. All intermediate data related to the node can be safely disposed. \n\n### onReuse\n\nCmn \nAdded in [1.4.0](/jetpack/androidx/releases/compose-runtime#1.4.0) \n\n```\nfun onReuse(): Unit\n```\n\nInvoked when the node was reused in the composition. Consumers might use this callback to reset data associated with the previous content, as it is no longer valid."]]