What do the return values of node.js process.memoryUsage() stand for?

From the official documentation (source):

process.memoryUsage()

Returns an object describing the memory usage of the Node process measured in bytes.

var util = require('util');

console.log(util.inspect(process.memoryUsage()));

This will generate:

{ rss: 4935680, heapTotal: 1826816, heapUsed: 650472 }

heapTotal and heapUsed refer to V8's memory usage.

Exactly what do rss, heapTotal, and heapUsed stand for?

It might seem like a trivial question, but I've been looking and I could not find a clear answer so far.


In order to answer this question, one has to understand V8’s Memory Scheme first.

A running program is always represented through some space allocated in memory. This space is called Resident Set. V8 uses a scheme similar to the Java Virtual Machine and divides the memory into segments:

  • Code: the actual code being executed
  • Stack: contains all value types (primitives like integer or Boolean) with pointers referencing objects on the heap and pointers defining the control flow of the program
  • Heap: a memory segment dedicated to storing reference types like objects, strings and closures. enter image description here

Now it is easy to answer the question:

  • rss: Resident Set Size
  • heapTotal: Total Size of the Heap
  • heapUsed: Heap actually Used

Ref: http://apmblog.dynatrace.com/2015/11/04/understanding-garbage-collection-and-hunting-memory-leaks-in-node-js/


RSS is the resident set size, the portion of the process's memory held in RAM (as opposed to the swap space or the part held in the filesystem).

The heap is the portion of memory from which newly allocated objects will come from (think of malloc in C, or new in JavaScript).

You can read more about the heap at Wikipedia.