Skip to main content
Built and battle-tested at Meta

Find memory leaks in JavaScript

Analyzes JavaScript heap and finds memory leaks in browser and node.js

$ npm install -g memlab
memlab run
$ memlab run --scenario test.js
MemLab found 46 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
--1 (element)---> [EventListener](native) @131009888
--context (internal)---> [<function scope>](object) @181905
--bigArray (variable)---> [Array](object) @182925 [8.3MB]

Finding leaks in production at

FacebookInstagramMessengerWhatsApp WebWorkplace

Features

Everything you need to chase down memory

From automated end-to-end leak detection to low-level heap analysis — in the browser, in Node.js, and in CI.

How it works

Three steps to a leak trace

Write a scenario, run it, and read the reference chain that keeps your objects alive.

1

Define your test

Describe the interaction you want to check for leaks.

// test.js
function url() {
return 'https://www.google.com/maps';
}
async function action(page) {
await page.click('text/Hotels');
}
async function back(page) {
await page.click('[aria-label="Close"]');
}
module.exports = {action, back, url};
2

Run memlab in the CLI

One command drives the browser and reports leak traces.

$ memlab run --scenario test.js
# Analyze duplicated strings in the heap
$ memlab analyze string
# Check unbound object growth
$ memlab analyze unbound-object
# Get shapes with unbound growth
$ memlab analyze unbound-shape
# Discover more memory analyses
$ memlab analyze -h
3

Or use the API

Take snapshots and find leaks programmatically.

const {findLeaks, takeSnapshots} = require('@memlab/api');
async function test() {
const scenario = {
url: () => 'https://www.facebook.com',
};
const result = await takeSnapshots({scenario});
const leaks = findLeaks(result);
// ...
}

Retainer traces

See exactly what is holding memory

memlab walks the reference chain from the GC root down to the leaked object, so you know which reference to break instead of guessing. Similar leaks are clustered, so 46 leaked objects become a handful of real bugs to fix.

Read the debugging guide →
memlab comparing heap snapshots to surface a leak trace

Start finding leaks in minutes

Install the CLI, point it at a page, and let memlab do the snapshot diffing for you.

$ npm install -g memlab