Skip to content

Commit

Permalink
doc: revise process.memoryUsage() text
Browse files Browse the repository at this point in the history
Some general edits, but also adding an explanation of why one might
choose process.memoryUsage.rss() over process.memoryUsage().rss.

PR-URL: #36757
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Yash Ladha <yash@yashladha.in>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
  • Loading branch information
Trott authored and MylesBorins committed Aug 31, 2021
1 parent 1ebe7d7 commit 0c469b3
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -1573,26 +1573,19 @@ changes:
* `external` {integer}
* `arrayBuffers` {integer}

The `process.memoryUsage()` method returns an object describing the memory usage
of the Node.js process measured in bytes.

For example, the code:
Returns an object describing the memory usage of the Node.js process measured in
bytes.

```js
console.log(process.memoryUsage());
```

Will generate:

<!-- eslint-skip -->
```js
{
rss: 4935680,
heapTotal: 1826816,
heapUsed: 650472,
external: 49879,
arrayBuffers: 9386
}
// Prints:
// {
// rss: 4935680,
// heapTotal: 1826816,
// heapUsed: 650472,
// external: 49879,
// arrayBuffers: 9386
// }
```

* `heapTotal` and `heapUsed` refer to V8's memory usage.
Expand All @@ -1610,8 +1603,8 @@ Will generate:
When using [`Worker`][] threads, `rss` will be a value that is valid for the
entire process, while the other fields will only refer to the current thread.

The `process.memoryUsage()` method iterate over each page to gather
informations about memory usage which can be slow depending on the
The `process.memoryUsage()` method iterates over each page to gather
information about memory usage which might be slow depending on the
program memory allocations.

## `process.memoryUsage.rss()`
Expand All @@ -1628,7 +1621,8 @@ The Resident Set Size, is the amount of space occupied in the main
memory device (that is a subset of the total allocated memory) for the
process, including all C++ and JavaScript objects and code.

This is the same value as the one returned by `process.memoryUsage()`.
This is the same value as the `rss` property provided by `process.memoryUsage()`
but `process.memoryUsage.rss()` is faster.

```js
console.log(process.memoryUsage.rss());
Expand Down

0 comments on commit 0c469b3

Please sign in to comment.