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).
free
free[T: AnyType, //](pointer: UnsafePointer[T, MutExternalOrigin], /, layout: Layout[T])
Frees memory previously allocated with alloc.
The layout argument must match the one passed to the corresponding alloc
call. Passing a mismatched layout or a pointer not obtained from alloc is
undefined behavior.
Safety:
pointermust have been returned by a matching call toalloc.layoutmust equal the layout passed to thatalloccall.
Example:
var layout = Layout[String].single()
var ptr = alloc(layout)
ptr.init_pointee_move("Dynamic allocation!")
ptr.destroy_pointee()
free(ptr, layout)
Parameters:
- T (
AnyType): The type of the elements in the allocation.
Args:
- pointer (
UnsafePointer[T, MutExternalOrigin]): A pointer returned by a previous call toalloc. - layout (
Layout[T]): The layout used when the memory was allocated.