Node.js
Read Node.js process memory measurements
Use process.memoryUsage to inspect several different memory measurements. Heap usage, resident memory, and external allocations describe different parts of the process and should not be treated as interchangeable totals.
Worked example
Node.js example · save as example.mjs and run node example.mjs
const usage = process.memoryUsage();
for (const key of ["rss", "heapTotal", "heapUsed", "external", "arrayBuffers"]) {
console.log(key, Number.isFinite(usage[key]) && usage[key] >= 0);
}How it works
The reported fields are byte counts. HeapUsed concerns JavaScript heap allocation, while RSS includes resident process memory beyond that heap. ArrayBuffers is included within external accounting, so adding all the fields together would double-count some memory.
Limits and mistakes
One snapshot cannot prove a leak or establish the physical RAM installed in the machine. Garbage collection and allocator behavior can keep memory high after objects become unreachable. Track comparable workloads over time before drawing a conclusion.
Check the result
Expect true for each listed field. Record the runtime version, workload, and sampling point when comparing runs; a raw number without that context is difficult to interpret.
Sources
Reference documentation for the behavior used in this guide: