/memlab:memlab-find-web-leaksfrom MemLab
Finds memory leaks in web apps using memlab. Writes Puppeteer test scenarios (url, action, back), runs memlab, and interprets clustered leak traces to fix detached DOM elements, unmounted React components, or other retained objects.
Ships in MemLab. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
memlab loads the page, takes a heap snapshot, runs the interaction you suspect
(action), undoes it (back), and takes two more snapshots. Objects that
action allocated and that are still alive after back are leak candidates.
By default memlab reports detached DOM elements and unmounted React Fiber
nodes, grouped into clusters by retainer trace.
npm install -g memlab # or prefix every command with npx: npx memlab run ...
memlab version
Save a file such as scenario.js. Pick one interaction, and make back
its exact inverse:
// scenario.js
module.exports = {
// Page to load first. memlab takes the baseline snapshot here.
url: () => 'http://localhost:3000/',
// The interaction suspected of leaking. Target snapshot after this.
action: async page => {
await page.click('[data-testid="open-settings"]');
await page.waitForSelector('[data-testid="settings-dialog"]');
},
// Undo the interaction without reloading. Final snapshot after this.
back: async page => {
await page.click('[data-testid="close-settings"]');
await page.waitForSelector('[data-testid="settings-dialog"]', {hidden: true});
},
};
Rules that keep the result valid:
action or back. page.goto(), page.reload(),
location.reload() or a link that does a full page load start a new heap.
memlab detects this and stops with "The page is reloaded. MemLab cannot
analyze heap across page reloads." Client-side route changes are fine.back must really undo action. If the dialog stays open, its objects
are still in use and nothing is reported (or everything is).page is a Puppeteer Page. memlab 2.x uses Puppeteer 24: only use
methods from the Puppeteer API.
page.waitForXPath() no longer exists. Puppeteer locators have no
count() or first(); use page.$$(selector) to count elements.await every Puppeteer call.cookies (or in setup), not in action. Work done in
action that back doesn't undo shows up as leaks.repeat is only
for stress tests.All scenario callbacks, with examples, are in references/scenario-api.md.
memlab run --scenario scenario.js
When it fails or gets stuck, add --verbose for stack traces, --headful to
watch the browser, or --debug to pause after each step. Leave them off
otherwise. --work-dir <dir> saves the run somewhere other than the default
working directory (memlab get-default-work-dir).
MemLab found 1 leak(s)
--Similar leaks in this run: 4--
--Retained size of leaked objects: 8.3MB--
[Window] (native) @35847 [8.3MB]
--20 (element)---> [InternalNode] (native) @130981728 [8.3MB]
--1 (element)---> [EventListener] (native) @131009888 [8.3MB]
--1 (element)---> [V8EventListener] (native) @224808192 [8.3MB]
--1 (element)---> [eventHandler] (closure) @168079 [8.3MB]
--context (internal)---> [<function scope>] (object) @181905 [8.3MB]
--bigArray (variable)---> [Array] (object) @182925 [8.3MB]
--edge (edge type)---> [node name] (node type) @id [retained size].eventHandler closure is still registered as an event
listener, and its scope holds bigArray. The fix is to remove the listener
when the UI closes.data/out/leaks.txt.
memlab run also copies it to data/cur/leaks.txt, next to the three
snapshots s1–s3.heapsnapshot. Runs through @memlab/api leave it only in
data/out/.memlab trace --node-id <id>: the retainer trace for one object.memlab view-heap --snapshot <file>: interactive heap browser.memlab find-leaks --trace-all-objects to treat every object action
allocated as a leak, and narrow it with --trace-object-size-above <bytes>.
To keep a custom rule, add a leakFilter to the scenario.memlab analyze unbound-object (and the other memlab analyze plugins)
works on the snapshots from the last run.memlab class-trend --snapshot-dir <dir>
counts objects per class across the snapshots in a directory (for example
the run's data/cur) and lists the classes that grew at every step.
memlab class-diff --baseline <file> --target <file> compares two
snapshots; add --output json for a CI check.memlab find-objects --snapshot <file> --detached (or --name-pattern,
--min-retained-size 1MB) lists matching objects with the ids
memlab trace takes. memlab native-contexts --snapshot <file> finds a
removed iframe or window that is still reachable.memlab-analyze-heap-snapshot skill or the memlab MCP server.Change the code at the link you found, rebuild the app, and run the same scenario again. The cluster should be gone or its retained size much smaller. Report the trace before and after the fix.
To keep the check running in CI, see the memlab-memory-tests skill or the
continuous test guide.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
4 skills in this plugin
/memlab-analyze-heap-snapshotAnalyze JavaScript heap snapshots (.heapsnapshot files from Chrome, Edge, Node.js, Electron or React Native/Hermes) with memlab to find memory leaks, explain why objects stay in memory, and suggest fixes. Use when the user shares or mentions a heap snapshot, asks why memory or heap size keeps growing, sees an out-of-memory crash, detached DOM elements, a growing cache or listener count, or wants to compare snapshots taken before and after a change. Works through the memlab MCP server tools (memlab_*) or, without MCP, the memlab-cli command from the @memlab/mcp-server npm package./memlab-capture-heap-snapshotsCapture JavaScript heap snapshots (.heapsnapshot files) for memory analysis from Chrome or Edge, Puppeteer, Playwright, Node.js, Electron or React Native (Hermes), including a series of snapshots that shows what grows over repeated interactions. Use when the user needs a heap snapshot, a heap dump of a Node.js process or one taken near out-of-memory, wants to measure memory growth or a suspected leak, or asks how to take snapshots in a test so memlab can analyze them./memlab-memory-testsWrite automated memory leak tests with memlab. Use it for Node.js unit tests that assert an object was garbage collected (takeNodeMinimalHeap, tagObject, hasObjectWithClassName), for browser leak tests in CI that run a memlab scenario through @memlab/api and fail when leaks are found, and for checking heap snapshots from Playwright, Cypress or Puppeteer tests. Use when the user wants a regression test for a memory leak, asks how to assert that memory is released, or wants memory leak checks in Jest, Mocha, node:test or a CI pipeline.npx claudepluginhub meta/memlab --plugin memlabOther plugins' skills for the same job