liveBook · Manning

External memory

As explained in JavaScript in Depth

Memory used by objects managed outside the JavaScript heap, including native allocations and some buffer storage.

A process can show rising memory while heapUsed remains nearly flat. External memory explains this apparent mismatch: native data associated with JavaScript objects lives outside the garbage-collected heap. section 11.1.1

Creating a TypedArray or Buffer places a small wrapper object in the managed heap, while its byte storage is often allocated natively and counted as external. A 10 MB Buffer therefore adds roughly 10 MB to external but little to heapUsed. arrayBuffers reports the subset allocated by ArrayBuffer and SharedArrayBuffer. section 11.1.1

Use the metrics to narrow memory symptoms:

  • Treat rising heapUsed as evidence of accumulating JavaScript objects; treat rising external with stable heapUsed as evidence involving Buffers or ArrayBuffers. section 11.2.1
  • Interpret rising rss with stable heapUsed and external as native memory outside the JavaScript engine's management, potentially indicating a runtime bug. section 11.2.1
  • Sample process.memoryUsage() periodically for trend detection; production monitoring commonly reports these values to a metrics collector. section 11.1.1
console.log(process.memoryUsage());
 
// Prints:
{
  rss: 44732416,
  heapTotal: 5345280,
  heapUsed: 3785576,
  external: 1305759,
  arrayBuffers: 26080,
}

Inspect the runtime's reported rss, heap totals, heap usage, external memory, and ArrayBuffer storage in one snapshot. section 11.1.1

How JavaScript in Depth covers it

How deep it goes
Explains wrapper-versus-native allocation and metric relationships, then stops short of identifying retained objects.
Examples
Uses a 10 MB Buffer, a process.memoryUsage() snapshot, and contrasting growth patterns for heapUsed, external, and rss.
What it assumes
Assumes JavaScript objects and garbage collection, while defining managed heap, native storage, and the reported memory fields.
What you can do after
Diagnose memory-growth categories with process.memoryUsage() and decide when buffer, heap, or native investigation is warranted.
How it connects
Connects external memory with process.memoryUsage(), heapUsed, rss, Buffer, ArrayBuffer, SharedArrayBuffer, and garbage collection.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of JavaScript in Depth. The section links point to the parts of the book it draws on.