# DoNotRetain

Artifact: [androidx.compose.runtime:runtime-annotation](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/annotation/DoNotRetain.kt+class:androidx.compose.runtime.annotation.DoNotRetain) Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.10.0) Common/All
- Cmn

  ```
  @MustBeDocumented
  @Retention(value = AnnotationRetention.BINARY)
  @Target(allowedTargets = [AnnotationTarget.CLASS])
  annotation DoNotRetain
  ```

*** ** * ** ***

Annotates that a class should not be retained. Types annotated with `https://developer.android.com/reference/kotlin/androidx/compose/runtime/annotation/DoNotRetain` should not be used in the return type of the `calculation` lambda given to the `retain {}` method in `androidx.compose.runtime`, or as a key input to `retain`.

When present on a class, a lint error will be reported when the class or any of its subclasses appear as the generic type of a call to `retain` or as a `key` parameter. The associated inspection only checks the direct return type of the `calculation` lambda, but retained values should hold no strong references, direct or indirect, to any type marked as `https://developer.android.com/reference/kotlin/androidx/compose/runtime/annotation/DoNotRetain`.

Generally, this annotation is expected to be used on resources that will be leaked if they are retained. Additional or other rationale may be provided by specifying an `https://developer.android.com/reference/kotlin/androidx/compose/runtime/annotation/DoNotRetain#(kotlin.String)`, which will appear in the lint error message when applicable.

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/annotation/DoNotRetain#DoNotRetain(kotlin.String)(explanation: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/annotation/DoNotRetain#explanation()` An optional explanation of why this class should not be retained. | Cmn |

## Public constructors

### DoNotRetain

Cmn Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.10.0)

```
DoNotRetain(explanation: String = "")
```

## Public properties

### explanation

Cmn

```
val explanation: String
```

An optional explanation of why this class should not be retained. If this value is not an empty string, it will be presented in the error description at the callsite of offending usages of this type.