IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

dealloc

def dealloc[T: AnyType, //](var allocation: Allocation[T], /)

Deallocates the storage owned by an Allocation.

Consumes allocation and releases its memory. This is the primary way to dispose of an Allocation produced by alloc. To deallocate a bare ThinAllocation, wrap it in an Allocation with its original Layout first: dealloc(thin^.unsafe_with_layout(layout)).

Example:

from std.memory.alloc import alloc, dealloc, Layout

var allocation = alloc(Layout[Int64].single())
dealloc(allocation^)

Parameters:

  • T (AnyType): The type of the elements in the allocation.

Args:

  • allocation (Allocation[T]): The Allocation to deallocate. It is consumed by this call.