# DisposeAsync()

> Asynchronously disposes of the window and releases its resources.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine.Windowing](/engine/6000.7/script-reference/unityengine/windowing.md)
* **Assembly:** UnityEngine.WindowingModule

```csharp
public ValueTask DisposeAsync()
```

### Returns

| Type                                                                                 | Description                                                     |
| ------------------------------------------------------------------------------------ | --------------------------------------------------------------- |
| [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask) | A ValueTask that represents the asynchronous dispose operation. |

### Remarks

Use this method to dispose of a secondary window when you no longer need it. You cannot dispose of the main window. To close the main window, use [Application.Quit](/engine/6000.7/script-reference/unityengine/application/quit.md) instead.

The `DisposeAsync` method clears all registered position and resolution change callbacks before it disposes of the window. After disposal, this [GameWindow](/engine/6000.7/script-reference/unityengine/windowing/gamewindow.md) instance is no longer valid and you must not use it.

The following code example demonstrates how to use this method to dispose of a secondary window.

### Examples

```csharp
using UnityEngine;
using UnityEngine.Windowing;

public class DisposeWindowExample : MonoBehaviour
{
    GameWindow secondaryWindow;

    void Start()
    {
        var settings = new GameWindowCreationSettings(
            title: "Secondary Window",
            width: 800,
            height: 600,
            position: new Vector2Int(0, 0),
            cameraDisplayIndex: 1,
            displayInfo: GameWindow.Main.GetDisplayInfo(),
            fullScreenMode: FullScreenMode.Windowed,
            resizable: false
        );

        var op = GameWindowManager.Create(settings);
        op.completed += (AsyncOperation o) =>
        {
            secondaryWindow = ((CreateWindowAsyncOperation)o).window;
        };
    }

    async void DestroySecondaryWindow()
    {
        await secondaryWindow.DisposeAsync();
        Debug.Log("Secondary window disposed.");
    }
}
```
