# Memlab Find Web Leaks

Find memory leaks in a web app with memlab.

- Repository: https://github.com/meta/memlab (5081 stars)
- Category: Design
- License: MIT
- Last updated: 2026-10-31
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add meta/memlab --skill memlab-find-web-leaks -g -a claude-code -y`
Codex: `npx skills add meta/memlab --skill memlab-find-web-leaks -g -a codex -y`
Cursor: `npx skills add meta/memlab --skill memlab-find-web-leaks -g -a cursor -y`
Gemini CLI: `npx skills add meta/memlab --skill memlab-find-web-leaks -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add meta/memlab`

## Description

Find 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.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Find memory leaks in a web app with memlab

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.

## 1. Install

```bash
npm install -g memlab   # or prefix every command with npx: npx memlab run ...
memlab version
```

## 2. Write the scenario

Save a file such as `scenario.js`. Pick **one** interaction, and make `back`
its exact inverse:

```javascript
// 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:

The rest: https://github.com/meta/memlab/blob/HEAD/plugins/memlab/skills/memlab-find-web-leaks/SKILL.md
