Skip to main content

memlab script-census

Report the source text of loaded scripts kept in a heap snapshot, and scripts kept in memory more than once

memlab script-census --snapshot <HEAP_SNAPSHOT_FILE>

Examples​

memlab script-census --snapshot <HEAP_SNAPSHOT_FILE> --top 50 --output json

Example output​

$ memlab script-census --snapshot /tmp/memlab-example/leak/data/cur/s3.heapsnapshot
Snapshot  /tmp/memlab-example/leak/data/cur/s3.heapsnapshot
  5 scripts keep 14.0 KB of source text, 0.7% of the heap
script                                                                  scripts  copies  source  extra copies
----------------------------------------------------------------------  -------  ------  ------  ------------
"(() => { const module = {}; \"use strict\";var g=Object.defineProp...        1       1  9.5 KB             -
http://localhost:3000/                                                       1       1  2.7 KB             -
"(function addPageBinding(type, name, prefix) { // Depending on the...        1       1  1.7 KB             -
"() {}"                                                                       1       1     0 B             -
"(empty source)"                                                              1       1     0 B             -

How to read the output​

memlab script-census lists the scripts whose source text is kept in memory, grouped by URL (or by the beginning of the source for scripts without one).

  • scripts is the number of script objects, and copies is the number of distinct copies of the source text.
  • source is the size of the source text kept.
  • extra copies is the memory spent on duplicate copies of the same source. A large value usually means the same bundle is loaded more than once, for example in several iframes.

This small app keeps 14.0 KB of source: its own page (http://localhost:3000/) and helper scripts injected by the browser automation.

Options​

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

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