Resident set size (RSS) measures the physical memory currently allocated to a process by the operating system. A Node.js process’s RSS includes the JavaScript heap, loaded runtime code, native addon memory, thread stacks, and other memory it has touched. Because it is visible to operating-system tools and container limits, RSS can rise even when JavaScript objects are not accumulating. section 11.1.1
Interpret RSS alongside the other process.memoryUsage() values:
- heapUsed measures live JavaScript objects and is the closest indicator of current managed-heap usage. section 11.1.1
- heapTotal measures memory reserved by the JavaScript engine for its managed heap; it can remain larger than heapUsed after collection. section 11.1.1
- external measures native memory associated with JavaScript objects, especially Buffer and TypedArray storage; arrayBuffers reports its ArrayBuffer and SharedArrayBuffer subset. section 11.1.1
- A rising RSS with stable heapUsed and external points toward native memory outside JavaScript-engine management, potentially indicating a runtime bug. section 11.2.1
A misleading memory leak
A healthy garbage-collection pattern produces repeated RSS or heap sawtooth behavior with stable troughs. If troughs steadily rise, objects are surviving collection cycles. If only RSS rises while heapUsed and external remain stable, investigate native allocations rather than assuming a JavaScript-object leak. section 11.2.1 section 11.6
console.log(process.memoryUsage());
// Prints:
{
rss: 44732416,
heapTotal: 5345280,
heapUsed: 3785576,
external: 1305759,
arrayBuffers: 26080,
}Inspect RSS beside heapTotal, heapUsed, external, and arrayBuffers in a single process.memoryUsage() snapshot. section 11.1.1
