destroy

fun destroy()

Cleans up the Experience when no longer in use, releasing the resources it holds.

Call this exactly where the view's own lifetime ends, which is not always where the surrounding screen's does:

  • Views and Fragments: pass the host LifecycleOwner's lifecycle to androidx.lifecycle.Lifecycle.addObserver and this is called for you on ON_DESTROY.

  • Compose: call it from AndroidView's onRelease, the counterpart to the factory that created the view. A DisposableEffect is scoped to the composable, so it will not fire when the AndroidView alone leaves the composition: inside an if, a lazy list, or a dialog that is dismissed while its screen stays put.

Safe to call more than once; subsequent calls are ignored. The view cannot be reused afterwards.