# ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed

Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/platform/ViewCompositionStrategy.android.kt+class:androidx.compose.ui.platform.ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Common/AllAndroid/JVM
- android

  ```
  object ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed : ViewCompositionStrategy
  ```

*** ** * ** ***

`https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/ViewCompositionStrategy` that disposes the composition when the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` returned by `https://developer.android.com/reference/kotlin/androidx/lifecycle/package-summary#(android.view.View).findViewTreeLifecycleOwner()` of the next window the view is attached to is `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.Event#ON_DESTROY`. This strategy is appropriate for Compose UI views that share a 1-1 relationship with their closest `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`, such as a Fragment view.

## Summary

| ### Public functions |
|---|---|---|
| `open () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed#installFor(androidx.compose.ui.platform.AbstractComposeView)(view: https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/AbstractComposeView)` Install this strategy for `https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/ViewCompositionStrategy#installFor(androidx.compose.ui.platform.AbstractComposeView)` and return a function that will uninstall it later. | android |

## Public functions

### installFor

android

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

Install this strategy for `https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/ViewCompositionStrategy#installFor(androidx.compose.ui.platform.AbstractComposeView)` and return a function that will uninstall it later. This function should not be called directly; it is called by `https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/AbstractComposeView#setViewCompositionStrategy(androidx.compose.ui.platform.ViewCompositionStrategy)` after uninstalling the previous strategy.