Get a Heap Snapshot
The MCP server analyzes heap snapshots: .heapsnapshot files, and
.heaptimeline files recorded with allocation tracking on. Save them where
the server can read them. Gzipped snapshots (<file>.gz) load too.
From Chrome DevTools
- Open DevTools (F12) and go to the Memory tab.
- Select Heap snapshot and click Take snapshot.
- Right-click the snapshot in the left panel and choose Save....
To record where objects were allocated, choose Allocations on timeline
instead, and save the .heaptimeline file. Then memlab_allocation_sites groups live objects by
the stack that allocated them.
From a Live Page
The assistant can take snapshots of a running page itself, including its dedicated workers, which a page snapshot never contains.
Start Chrome with remote debugging on, in a separate profile (Chrome 136 and later ignore the port flag on your default profile), by passing these flags:
--remote-debugging-port=9222 --user-data-dir=<a temporary directory>Open your page in that Chrome.
Ask the assistant to take a snapshot with
memlab_capture, into an output directory. Withlist_targets: true, it lists the pages to choose from.
Give each capture a label. Later, wherever a snapshot path is accepted, the
assistant can refer to it as checkpoint:<label>. For example, it can compare
two captures with
memlab_diff_snapshots({before: "checkpoint:baseline", after: "checkpoint:after"}).
memlab_realm_summary compares the page with its workers.
To check an idea against the running app, memlab_live_eval evaluates one
expression in the page and returns its value as JSON. It refuses any
expression that V8 can't prove is free of side effects, unless
allow_side_effects is set, and stops after timeout_s seconds.
Both tools attach to the browser on port. Without one they use
MEMLAB_CDP_PORT, then the CDP port a leak-hunt round's run.json records
(config.cdp_port, from the run_dir passed, the run the server read last,
or the active snapshot's round), and only then 9222, which is often some
other Chrome. That round's url_filter applies too, when the caller passed
none. Every reply names the page it attached to and where the port came
from, for example on port 9444 (from r12/run.json).
From Node.js
const v8 = require('v8');
const snapshot = v8.writeHeapSnapshot(undefined, {exposeNumericValues: true});
console.log(`Heap snapshot written to ${snapshot}`);
Capture Numbers
A snapshot records the value of every number only when it is taken with
numeric values on: Include numerical values in capture in DevTools,
captureNumericValue: true over the DevTools protocol, or
exposeNumericValues: true in Node.js. A cap such as maxSize: 1000, a
counter and a timer's delay are numbers, so without them the server can tell
neither a bounded collection from a leak nor how long a cleanup timer waits.
memlab_bound_evidence then answers numbers not captured, and
helpers.value(id) in memlab_eval and memlab_get_value return no value.
In such a capture each number points at a string holding its text; class
censuses (the class rows of memlab_verdict_table, the sidecar index and
the class histograms) count those strings as one class, (number value),
not one class per value such as 0 or 0.025000005960464478.
From memlab
memlab run and memlab snapshot
save a snapshot after each step of a scenario, in the data/cur directory
of their working directory (memlab get-default-work-dir prints the
default). The server loads them as they are.
To measure growth, take a series of snapshots while an interaction repeats: see Snapshot Ladders.