---
title: "Composition"
description: "A composition object is usually constructed for you, and returned from an API that is used to
initially compose a UI. For instance, [setContent] returns a Composition.

The [dispose] method should be used when you would like to dispose of the UI and the Composition."
type: "interface"
---

<div class='type'>Interface</div>


<a id='references'></a>

<div class='sourceset sourceset-common'>Common</div>



```kotlin
public interface Composition
```


A composition object is usually constructed for you, and returned from an API that is used to
initially compose a UI. For instance, `setContent` returns a Composition.

The `dispose` method should be used when you would like to dispose of the UI and the Composition.


## Functions

```kotlin
public fun dispose()
```


Clear the hierarchy that was created from the composition and release resources allocated for
composition. After calling `dispose` the composition will no longer be recomposed and calling
`setContent` will throw an `IllegalStateException`. Calling `dispose` is idempotent, all
calls after the first are a no-op.


```kotlin
public fun setContent(content: @Composable () -> Unit)
```


Update the composition with the content described by the `content` composable. After this has
been called the changes to produce the initial composition has been calculated and applied to
the composition.

Will throw an `IllegalStateException` if the composition has been disposed.

#### Parameters

| | |
| --- | --- |
| content | A composable function that describes the content of the composition. |




