# Memlab Memory Tests

Write automated memory leak tests with memlab.

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

## Install

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

## Description

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

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

# Memory leak tests with memlab

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](#nodejs-heap-assertions) |
| A web UI interaction | [memlab scenario run from the test job](#browser-leak-tests-in-ci) |
| An existing Playwright, Cypress or Puppeteer test | [Snapshots from the existing test](#snapshots-from-an-existing-e2e-test) |

## Node.js heap assertions

`takeNodeMinimalHeap()` from `@memlab/core` snapshots the current process and
returns a queryable heap. Assert that the object you released is gone:

```javascript
// 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);
```

```bash
npm install --save-dev @memlab/core
```

The rest: https://github.com/meta/memlab/blob/HEAD/plugins/memlab/skills/memlab-memory-tests/SKILL.md
