Android 12 Developer Preview is here! Try it out, and give us your feedback!

DisposeOnDetachedFromWindow

object DisposeOnDetachedFromWindow : ViewCompositionStrategy
kotlin.Any
   ↳ androidx.compose.ui.platform.ViewCompositionStrategy.DisposeOnDetachedFromWindow

ViewCompositionStrategy that disposes the composition whenever the view becomes detached from a window. If the user of a Compose UI view never explicitly calls AbstractComposeView.createComposition, this strategy is always safe and will always clean up composition resources with no explicit action required - just use the view like any other View and let garbage collection do the rest. (If AbstractComposeView.createComposition is called while the view is detached from a window, AbstractComposeView.disposeComposition must be called manually if the view is not later attached to a window.)

DisposeOnDetachedFromWindow is the default strategy for AbstractComposeView and ComposeView.

Summary

Public methods
() -> Unit

Install this strategy for view and return a function that will uninstall it later.

Public methods

installFor

fun installFor(view: AbstractComposeView): () -> Unit

Install this strategy for view and return a function that will uninstall it later. This function should not be called directly; it is called by AbstractComposeView.setViewCompositionStrategy after uninstalling the previous strategy.