liveBook · Manning

Resident set size

As explained in JavaScript in Depth

A process-memory metric representing resident set size, the amount of process memory currently held in physical memory.

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

How JavaScript in Depth covers it

How deep it goes
Defines RSS’s included regions and contrasts it with heap metrics, then uses metric trends to distinguish JavaScript, external, and native growth.
Examples
Uses process.memoryUsage() output and healthy-versus-leaking sawtooth memory graphs to interpret RSS trends.
What you can do after
Diagnose memory growth by comparing RSS with heapUsed and external over time before using heap snapshots or heavier tools.
How it connects
Connects RSS with process.memoryUsage(), heapUsed, heapTotal, external memory, garbage collection, memory leaks, and native memory.

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.