← All docs

memory_get_usage()

Returns live native heap bytes, including block headers and allocator rounding. With real_usage=true returns the fixed heap arena capacity, including unused space. Excludes concat scratch, libc, and Rust bridge allocations.

memory_get_usage()

function memory_get_usage(bool $real_usage = false): int

Returns live native heap bytes, including block headers and allocator rounding. With real_usage=true returns the fixed heap arena capacity, including unused space. Excludes concat scratch, libc, and Rust bridge allocations.

Parameters:

  • $real_usage (bool), default false, optional

Returns: int

Availability

Compiled (AOT)Magician (eval)
AvailableAvailable

Examples:

$before = memory_get_usage();
$values = array_fill(0, 10000, 1);
echo memory_get_usage() - $before;

Internals

For how memory_get_usage is implemented in the compiler, see the internals page.