Basic module

array_free

procedure · 2 overloadsSource

Frees the storage of an array. A view is freed with free, i.e. through context.allocator; a dynamic array goes back to the allocator it grew with.

The argument is not changed, so it dangles afterwards: use array_reset to free and clear in one go. Freeing an array that was never allocated (a zero-initialized one) is fine. Elements that own memory are not freed.

ExampleOpen in playground ↗
values: [..] int;
array_add(*values, 1, 2, 3);
array_free(values);
values = .{};
array_free :: (array: [] $T)

Frees the storage of an array. A view is freed with free, i.e. through context.allocator; a dynamic array goes back to the allocator it grew with.

The argument is not changed, so it dangles afterwards: use array_reset to free and clear in one go. Freeing an array that was never allocated (a zero-initialized one) is fine. Elements that own memory are not freed.

Parameters

array: [] $T
ExampleOpen in playground ↗
values: [..] int;
array_add(*values, 1, 2, 3);
array_free(values);
values = .{};
array_free :: (array: [..] $T)

Frees a dynamic array through the allocator it grew with, or context.allocator if it never allocated.

Parameters

array: [..] $T

See also