Skip to main content

memlab heap-stats

Split the memory in a heap snapshot into code, strings, JS arrays, system objects and native memory, and into loaded code vs memory the program allocated

memlab heap-stats --snapshot <HEAP_SNAPSHOT_FILE>

Examples​

memlab heap-stats --snapshot <HEAP_SNAPSHOT_FILE> --output json

Example output​

$ memlab heap-stats --snapshot /tmp/memlab-example/leak/data/cur/s3.heapsnapshot
Snapshot  /tmp/memlab-example/leak/data/cur/s3.heapsnapshot
statistics            size   share
----------------  --------  ------
total               2.0 MB  100.0%
V8 heap             1.3 MB   62.9%
  code             45.4 KB    2.2%
  strings          54.3 KB    2.6%
  JS arrays       783.0 KB   37.3%
  system objects       0 B    0.0%
  other           437.3 KB   20.8%
native            779.1 KB   37.1%
  typed arrays         0 B    0.0%

why the memory exists                   size  share
-----------------------------------  -------  -----
script source text                   14.0 KB   0.7%
compiled code and function metadata  45.4 KB   2.2%
allocated by the program              2.0 MB  97.2%

How to read the output​

memlab heap-stats breaks down the memory in one snapshot.

The first table splits the total by where the memory lives:

  • V8 heap is what the JavaScript engine manages, split into code, strings, JS arrays (including the storage behind arrays and object elements), system objects, and everything else.
  • native is memory held outside the JavaScript heap, such as DOM nodes and the data behind typed arrays.

The second table splits the same total by why the memory exists: the source text of scripts, compiled code and function metadata, and objects the program allocated.

In this example, JS arrays is 37.3% of the heap, which is unusual for a page this small. The leaked dialog keeps an 800KB history array, and memlab class-histogram and memlab analyze object-size point to it.

Options​

  • --snapshot: set file path of the heap snapshot under analysis
  • --engine: set the JavaScript engine (default to V8)
  • --output: output format of the report: 'text' (default) or 'json'

The universal options (--help, --verbose, ...) work with this command too.