# ForgetfulRetainedValuesStore

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

  ```
  object ForgetfulRetainedValuesStore : RetainedValuesStore
  ```

*** ** * ** ***

The `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/ForgetfulRetainedValuesStore` is an implementation of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainedValuesStore` that is incapable of retaining any exited values. When installed as the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/package-summary#LocalRetainedValuesStore()`, all invocations of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/retain.composable#retain(kotlin.Function0)` will behave like a standard `https://developer.android.com/reference/kotlin/androidx/compose/runtime/remember.composable#remember(kotlin.Function0)`. `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainObserver` callbacks are still dispatched instead of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/RememberObserver` callbacks, meaning that this class will always immediately `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainObserver#onRetired()` a value as soon as it exits composition.

A `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/ForgetfulRetainedValuesStore` can be installed arbitrarily in any number of compositions.

## Summary

| ### Public functions |
|---|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/ForgetfulRetainedValuesStore#consumeExitedValueOrDefault(kotlin.Any,kotlin.Any)(key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html, defaultValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` If this store is currently retaining exited values and has a value previously created with the given `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainedValuesStore#consumeExitedValueOrDefault(kotlin.Any,kotlin.Any)`, its original record is returned and removed from the list of exited kept objects that this store is tracking. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/ForgetfulRetainedValuesStore#onContentEnteredComposition()()` Invoked to indicate that all content has finished entering the composition for the first time after the store is installed. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/ForgetfulRetainedValuesStore#onContentExitComposition()()` Invoked to indicate that the associated content is *about* to start leaving composition. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/ForgetfulRetainedValuesStore#saveExitingValue(kotlin.Any,kotlin.Any)(key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html, value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` Invoked when a retained value is exiting composition while this store is retaining exited values. | Cmn |

## Public functions

### consumeExitedValueOrDefault

Cmn

```
open fun consumeExitedValueOrDefault(key: Any, defaultValue: Any?): Any?
```

If this store is currently retaining exited values and has a value previously created with the given `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainedValuesStore#consumeExitedValueOrDefault(kotlin.Any,kotlin.Any)`, its original record is returned and removed from the list of exited kept objects that this store is tracking.

This method is always called from the composition thread.

| Parameters |
|---|---|
| `key: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html` | The keys to resolve a retained value that has left composition |
| `defaultValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A value to be returned if there are no retained values that have exited composition and are being held by this RetainedValuesStore for the given `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainedValuesStore#consumeExitedValueOrDefault(kotlin.Any,kotlin.Any)`. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | A retained value for `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainedValuesStore#consumeExitedValueOrDefault(kotlin.Any,kotlin.Any)` if there is one and it hasn't already re-entered composition, otherwise `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainedValuesStore#consumeExitedValueOrDefault(kotlin.Any,kotlin.Any)`. |

### onContentEnteredComposition

Cmn

```
open fun onContentEnteredComposition(): Unit
```

Invoked to indicate that all content has finished entering the composition for the first time after the store is installed. Any unconsumed retained values should be discarded at this time.

This function is called by the library when the store is installed with `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/LocalRetainedValuesStoreProvider.composable#LocalRetainedValuesStoreProvider(androidx.compose.runtime.retain.RetainedValuesStore,kotlin.Function0)`. It should not be invoked directly in production code. The default installation will always invoke this callback on the applier thread for the content's latest destination, which may differ when moved between compositions.

Implementors of this function MUST call `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainObserver#onRetired()` for all discarded values that implement `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainObserver` following the threading guarantees specified in `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainObserver`'s documentation.

### onContentExitComposition

Cmn

```
open fun onContentExitComposition(): Unit
```

Invoked to indicate that the associated content is *about* to start leaving composition. The store should make any necessary preparations to start retaining values as they exit the composition.

This function is called by the library when the store is installed with `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/LocalRetainedValuesStoreProvider.composable#LocalRetainedValuesStoreProvider(androidx.compose.runtime.retain.RetainedValuesStore,kotlin.Function0)`. It should not be invoked directly in production code. The default installation will always invoke this callback on the applier thread that content entered composition on.

### saveExitingValue

Cmn

```
open fun saveExitingValue(key: Any, value: Any?): Unit
```

Invoked when a retained value is exiting composition while this store is retaining exited values. It is up to the implementation of this method to decide whether and how to store these values so that they can later be retrieved by `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainedValuesStore#consumeExitedValueOrDefault(kotlin.Any,kotlin.Any)`.

The given `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainedValuesStore#saveExitingValue(kotlin.Any,kotlin.Any)` are not guaranteed to be unique. To handle duplicate keys, implementors should return retained values with the same keys from `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainedValuesStore#consumeExitedValueOrDefault(kotlin.Any,kotlin.Any)` in the opposite order they are received by `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainedValuesStore#saveExitingValue(kotlin.Any,kotlin.Any)`.

If the implementation of this store does not accept this value into its kept exited object list, it MUST call `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainObserver#onRetired()` if `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainedValuesStore#saveExitingValue(kotlin.Any,kotlin.Any)` implements `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainObserver`, following the threading guarantees specified in `https://developer.android.com/reference/kotlin/androidx/compose/runtime/retain/RetainObserver`'s documentation.

This method is always called from the applier thread.