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
