estimateShallowMemoryUsageOf

Bun

Symbol

estimateShallowMemoryUsageOf

function estimateShallowMemoryUsageOf(value: string | bigint | symbol | object | CallableFunction): number

Non-recursively estimate the memory usage of an object, excluding the memory usage of properties or other objects it references. For more accurate per-object memory usage, use Bun.generateHeapSnapshot.

This is a best-effort estimate. It may not be 100% accurate. When it's wrong, it may mean the memory is non-contiguous (such as a large array).

Passing a primitive type that isn't heap allocated returns 0.