# Dispose()

> Destroys the NavQueryBuffer and deallocates all memory used by it.

## Definition

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

```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/6000.5/script-reference/unity/ai/navigation/lowlevel/navworld.md) pathfinding call that receives it throws an exception when executed in the Editor. Each NavQueryBuffer you create must be paired with exactly one call to [NavQueryBuffer.Dispose](/engine/6000.5/script-reference/unity/ai/navigation/lowlevel/navquerybuffer/dispose.md).

### Examples

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

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();
    }
}
```
