Skills

Memlab Find Web Leaks

Find memory leaks in a web app with memlab.

Install

npx skills add meta/memlab --skill memlab-find-web-leaks -g -a claude-code -y
Repository
meta/memlab5.1k
Category
Design
Updated
4d ago
License
MIT
Context cost
Lightabout 1,354 tokens
Runs scripts
No, instructions only

What it does

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.

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

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:

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

Read the whole SKILL.md on GitHub

More in Design