Skip to main content

memlab view-heap

Interactive command to view a single heap snapshot

memlab view-heap --snapshot <HEAP_SNAPSHOT_FILE>

Example output​

$ memlab view-heap --snapshot /tmp/memlab-example/leak/data/cur/s3.heapsnapshot
┌─Referrers of @65963 (press 1 ─┐┌─Clustered Objects (press 3 to ┐┌─References of @65963 (press 4 ─┐
│[blink::FormController](native)││[Cluster] [Detached <div       ││--7(element)---> [Detached <div │
│[Detached <button id="close-set││                               ││--5(element)---> [Detached      │
│[Detached <div>](native)       ││                               ││--6(element)---> [HTMLDocument](│
│[Detached <div>](native)       ││                               ││--3 / part of key (<div         │
│[Detached <div>](native)       ││                               ││--4(element)---> [Detached      │
│[Detached <div>](native)       ││                               ││--__proto__(property)---> [HTMLD│
│[Detached <div>](native)       ││                               ││--map(internal)---> [system /   │
│[Detached <div>](native)       ││                               ││                                │
│[Detached <div>](native)       ││                               │└────────────────────────────────┘
│[Detached <div>](native)       ││                               │┌─Retainer Trace of @65963  ─────┐
│[Detached <div>](native)       ││                               ││[Window / http://localhost:3000│
│[Detached <div>](native)       ││                               ││--global_object(shortcut)---> [W│
│[Detached <div>](native)       ││                               ││--openedDialogs(property)---> [S│
└───────────────────────────────┘│                               ││--table(internal)---> [](array) │
┌─Objects (press 2 to focus) 1 ─┐│                               ││--5(internal)---> [Detached     │
│[Detached] [Detached <div      ││                               ││                                │
│                               ││                               ││                                │
│                               ││                               ││                                │
│                               │└───────────────────────────────┘│                                │
│                               │┌─Object: @65963 (press 5 to ───┐│                                │
│                               ││id: @65963                     ││                                │
│                               ││name: Detached <div class="sett││                                │
│                               ││type: native                   ││                                │
│                               ││self size: 104 bytes           ││                                │
│                               ││retained size: 45.3KB          ││                                │
│                               ││# of references: 7             ││                                │
│                               ││# of referrers: 245            ││                                │
└───────────────────────────────┘└───────────────────────────────┘└────────────────────────────────┘
 Keys: ↑ ↓ ← → Enter(select) f(full screen) q(quit) 1 2 3 4 5 6

How to read the output​

memlab view-heap opens an interactive viewer in the terminal. It starts with a list of objects worth a look: the detached DOM elements and the objects with the largest retained size. Press a number to move to a panel, the arrow keys to move within it, and Enter to select an object. Press f to show the panel full screen, and q to leave full screen. The panels are:

  1. Referrers of the selected object, i.e. what references it. Here these are the 240 rows, the close button, and other objects that point back to the dialog's <div class="settings">.
  2. Objects, the starting list. Each entry is tagged with why it is listed, like [Detached].
  3. Clustered Objects, similar objects grouped together.
  4. References of the selected object, i.e. what it references.
  5. Object: details of the selected object, including its retained size, its numbers of references and referrers, and its dominator (the closest object that every path from a GC root goes through).
  6. Retainer Trace: the chain of references that keeps the selected object alive. Here it goes through the global openedDialogs Set.

Selecting an object in panels 1, 4, or 6 makes it the selected object, so you can follow references in both directions.

On a wide screen, the example above is a recording of a session, with each key pressed shown below it. It opens on the closed dialog's <div class="settings"> and moves down its Referrers, which the other panels follow. It shows the Referrers full screen, then goes back to the dialog. In the Retainer Trace, it moves down to the openedDialogs Set and presses Enter, which adds the Set to the Objects panel as [Chosen]. Pressing 2 then shows the Set in the other panels. Press Replay to watch it again.

Options​

  • --snapshot: set file path of the heap snapshot under analysis
  • --engine: set the JavaScript engine (default to V8)
  • --node-id: set heap node ID
  • --ml-clustering: use machine learning algorithms for clustering leak traces (by default, traces are clustered by heuristics)
  • --work-dir: set the working directory of the current run
  • --heap-parser-dict-fast-store-size: the size threshold for switching from fast store to slower store in the heap snapshot parser. The default value is 5,000,000. If you get the FATAL ERROR: invalid table size Allocation failed - JavaScript heap out of memory error, try to decrease the threshold here

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