/memlab:memlab-memory-testsfrom MemLab
Writes automated memory leak tests with memlab: Node.js heap assertions (takeNodeMinimalHeap, tagObject, hasObjectWithTag), browser leak tests in CI via @memlab/api, and heap snapshot checks from Playwright, Cypress or Puppeteer tests.
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.
None: SKILL.md is the whole skill.
Pick the kind of test from what has to stay leak-free:
| Code under test | Test |
|---|---|
| A Node.js module, class or server code | Heap assertion in a unit test |
| A web UI interaction | memlab scenario run from the test job |
| An existing Playwright, Cypress or Puppeteer test | Snapshots from the existing test |
takeNodeMinimalHeap() from @memlab/core snapshots the current process and
returns a queryable heap. Assert that the object you released is gone:
// widget.memory.test.js (Jest; node:test and Mocha work the same way)
const {config, takeNodeMinimalHeap, tagObject} = require('@memlab/core');
const {Widget} = require('./widget');
test('Widget is released after dispose()', async () => {
config.muteConsole = true;
let widget = new Widget();
tagObject(widget, 'widget-under-test'); // marks it without changing it
widget.dispose();
widget = null;
const heap = await takeNodeMinimalHeap();
expect(heap.hasObjectWithTag('widget-under-test')).toBe(false);
}, 30000);
npm install --save-dev @memlab/core
tagObject(obj, tag) + heap.hasObjectWithTag(tag) checks one specific
instance. heap.hasObjectWithClassName('Widget') checks that no instance of
the class is left; heap.getAnyObjectWithClassName('Widget') returns one to
inspect. heap.hasObjectWithPropertyName(name) checks for any object with
that property.null) before
taking the heap, or the test itself keeps the object alive.takeNodeFullHeap() from @memlab/heap-analysis.
The minimal heap skips that computation to parse faster.dumpNodeHeapSnapshot() from @memlab/core and inspect it
(see the memlab-analyze-heap-snapshot skill).Write a scenario for the interaction (see the memlab-find-web-leaks skill),
then run it from the test job with @memlab/api and fail on leaks:
// settings-dialog.memory.test.js
const {run} = require('@memlab/api');
const scenario = require('./scenarios/settings-dialog');
test('settings dialog does not leak', async () => {
const {leaks} = await run({
scenario,
skipWarmup: true, // skip the server warm-up visits
consoleMode: 'CONTINUOUS_TEST', // no progress animation in CI logs
workDir: '/tmp/memlab/settings-dialog', // must exist; keep it as a CI artifact
});
expect(leaks.length).toBe(0);
}, 10 * 60 * 1000);
npm install --save-dev @memlab/api
run returns {leaks, runResult}. leaks is the list of clustered leak
traces; an empty list means no leaks were found. The work directory has the
snapshots and browser console output (data/cur/) and the readable traces
(data/out/leaks.txt). Upload it from CI so a failure can be investigated.CONTINUOUS_TEST mode skips screenshots and waits an extra 10 seconds after
the initial page load. Leave consoleMode out when you want screenshots of
each step.workDir before calling run (for example with
fs.mkdirSync(dir, {recursive: true})).run launches headless Chromium through Puppeteer. On Linux CI images,
install Chromium's shared libraries, or set chromiumBinary to a browser the
image already has.memlab run --scenario <file> --work-dir <dir> --sc, where --sc is the
continuous-test console mode. Assert on the result in a script with
BrowserInteractionResultReader and findLeaks from @memlab/api.Take three Chromium heap snapshots in the existing test: baseline (before the
interaction), target (after it) and final (after undoing it). The
memlab-capture-heap-snapshots skill has a CDP helper for Puppeteer and
Playwright. Then:
const {findLeaksBySnapshotFilePaths} = require('@memlab/api');
test('the flow under test does not leak', async () => {
// ...drive the flow and write the three snapshots...
const leaks = await findLeaksBySnapshotFilePaths(baselineFile, targetFile, finalFile);
expect(leaks.length).toBe(0);
}, 5 * 60 * 1000);
leakFilter that reports
"everything above N bytes" needs a threshold with headroom.memlab measure --scenario <file>
runs the scenario several times to show how much is noise.leakFilter
with a comment linking the issue, instead of disabling the test.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub meta/memlab --plugin memlab4 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-find-web-leaksFind memory leaks in a web app with memlab. Write a test scenario (url, action, back) that drives the page in Chromium through Puppeteer, run `memlab run`, read the clustered leak traces, and fix the code that keeps detached DOM elements, unmounted React components or other objects alive. Use when the user asks to check a page, component, modal, dialog, route or user flow for memory leaks, to write a memlab scenario, to set up memory leak tests for a web app, or to find out why memory is not released after a UI interaction is undone.Other plugins' skills for the same job