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

后端 未结 4 1139
你的背包
你的背包 2020-12-07 09:51

From the official documentation (source):

process.memoryUsage()

Returns an object describing the memory usage of the Node

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 10:07

    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.

    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/

提交回复
热议问题