# FreeMem
{: .no_toc }

Releases a block of memory previously obtained from [**AllocMem**](/tB/Modules/HiddenModule/AllocMem.md).

Syntax: **FreeMem** *MemPointer*

*MemPointer*
: *required* **LongPtr**. The address returned by a previous call to [**AllocMem**](/tB/Modules/HiddenModule/AllocMem.md).

The pointer is invalid after the call returns. Passing a pointer that did not come from **AllocMem**, or one that has already been freed, has undefined behaviour. A *MemPointer* of 0 does nothing.

### Common Errors

| Error | When |
|---|---|
| [94 (`&H5E`)](/Reference/Run-time-Errors.md#94), *Invalid use of Null* | *MemPointer* is **Null** |

### Example

This example allocates a buffer, uses it, and then releases it with **FreeMem**.

```tb check_build
Dim buf As LongPtr = AllocMem(256)
' ... write and read buf ...
FreeMem buf    ' release the block; buf is invalid after this point
```

### See Also

- [AllocMem](/tB/Modules/HiddenModule/AllocMem.md) function
