# ViewCompositionStrategy.DisposeOnDetachedFromWindow

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.DisposeOnDetachedFromWindow) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Common/AllAndroid/JVM
- android

  ```
  object ViewCompositionStrategy.DisposeOnDetachedFromWindow : ViewCompositionStrategy
  ```

*** ** * ** ***

`https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/ViewCompositionStrategy` that disposes the composition whenever the view becomes detached from a window. If the user of a Compose UI view never explicitly calls `https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/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 `https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/AbstractComposeView#createComposition()` is called while the view is detached from a window, `https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/AbstractComposeView#disposeComposition()` must be called manually if the view is not later attached to a window.)

## 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.DisposeOnDetachedFromWindow#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.