---
title: Dispose()
product: Unity Editor
version: '7000.0'
latest_version: '7000.0'
status: This page documents version 7000.0. The latest version is 7000.0.
canonical: https://docs.unity.com/en-us/engine/7000.0/script-reference/unity/ai/navigation/lowlevel/navquerybuffer/dispose
latest_url: https://docs.unity.com/en-us/engine/7000.0/script-reference/unity/ai/navigation/lowlevel/navquerybuffer/dispose.md
last_updated: 2026-11-30
generated_at: 2026-12-01T01:18:28.425Z
locale: en-us
---

# Dispose()

> Destroys the NavQueryBuffer and frees the memory it uses.

## Definition

* **Type:** Method
* **Namespace:** [Unity.AI.Navigation.LowLevel](/engine/7000.0/script-reference/unity/ai/navigation/lowlevel.md)
* **Assembly:** [UnityEngine.AIModule](/engine/7000.0/script-reference/modules/unityengine-aimodule.md)

```csharp
public void Dispose()
```

### Remarks

Call this method when the buffer is no longer needed. After you dispose it, the `NavQueryBuffer` can't be reused, and any subsequent [NavWorld](/engine/7000.0/script-reference/unity/ai/navigation/lowlevel/navworld.md) pathfinding call that receives it throws an exception when executed in the Editor. Call `Dispose` exactly once for each [NavQueryBuffer](/engine/7000.0/script-reference/unity/ai/navigation/lowlevel/navquerybuffer.md) you create.

### Examples

```csharp
using Unity.Collections;
using UnityEngine;
using Unity.AI.Navigation.LowLevel;

// Attach this script to a GameObject. When the GameObject is disabled, the script disposes the
// NavQueryBuffer and the NavWorld handle to free their native memory.
public class NavQueryBufferDisposeExample : MonoBehaviour
{
    NavWorld m_World;
    NavQueryBuffer m_Buffer;

    void OnEnable()
    {
        m_World = NavWorld.GetDefaultWorld();
        m_Buffer = new NavQueryBuffer(m_World, Allocator.Persistent, 1024);
    }

    void OnDisable()
    {
        // Release the native memory allocated by the constructor, then the world handle.
        m_Buffer.Dispose();
        m_World.Dispose();
    }
}
```
