9.4. Context and idle-fork memory observations

Context and retained idle-fork memory snapshots for runtime diagnostics. Sample on the owning context and publish value copies across threads.

9.4.1. Structures

ContextMemory

Memory sizes in bytes, sampled on the owning context.

Fields:
  • heap_used : uint64 - Live context heap bytes.

  • heap_reserved : uint64 - Reserved context heap bytes.

  • strings_used : uint64 - Live string heap bytes.

  • strings_reserved : uint64 - Reserved string heap bytes.

  • stack : uint64 - Context stack capacity.

  • globals : uint64 - Context global storage.

  • native_stack : uint64 - Current Emscripten thread stack capacity, zero elsewhere.

IdleForkMemory

Memory retained by idle forks; active jobs are excluded.

Fields:
  • count : uint64 - Retained idle context count.

  • memory : ContextMemory - Aggregate context sizes; native_stack is zero.

9.4.2. Context snapshots

context_idle_forks(): IdleForkMemory

Idle job contexts retained by this owner. Join jobs before sampling to include the complete pool. Active forks are excluded rather than reading changing heaps.

context_memory(): ContextMemory

Samples the calling context. Publish the returned value copy across threads.