memlab is an end-to-end testing and analysis framework for identifying
JavaScript memory leaks and optimization opportunities.
Online Resources: [Website] | [Documentation] | [Meta Eng Blog Post] | [Tech Talk] | [AI Assistant Guide]
Features:
- Browser memory leak detection - Write test scenarios with the Puppeteer
API, and memlab will automatically compare JavaScript heap snapshots, filter
out memory leaks, and aggregate the results
- Object-oriented heap traversal API - Supports the creation of
custom memory leak detectors, and enables programmatic analysis of JS heap
snapshots taken from Chromium-based browsers, Node.js, Electron.js, and Hermes
- Memory CLI toolbox - Built-in toolbox and APIs for finding memory
optimization opportunities (not necessarily just memory leaks)
- MemLens: Browser Memory Debugging Tools - Enables visualization of memory
leaks and interactive memory debugging in the browser.
- Memory assertions in Node.js - Enables unit tests or running node.js
programs to take a heap snapshot of their own state, perform self memory
checking, or write advanced memory assertions
- MCP server for AI coding assistants - Provides an MCP server that gives
AI coding assistants (Claude Code, Cursor, etc.) interactive tools to load
heap snapshots, find memory leaks, and investigate optimization opportunities
through natural language conversation

CLI Usage
Install the CLI
npm install -g memlab
Find Memory Leaks
To find memory leaks in Google Maps, you can create a
scenario file defining how
to interact with Google Maps. Let's call it test-google-maps.js:
// initial page load url: Google Maps
function url() {
return 'https://www.google.com/maps/@37.386427,-122.0428214,11z';
}
// action where we want to detect memory leaks: click the Hotels button
async function action(page) {
// puppeteer page API
await page.click('text/Hotels');
}
// action where we want to go back to the step before: click clear search
async function back(page) {
// puppeteer page API
await page.click('[aria-label="Close"]');
}
module.exports = {action, back, url};
Now run memlab with the scenario file, memlab will interact with
the web page and detect memory leaks with built-in leak detectors:
memlab run --scenario test-google-maps.js
memlab will print memory leak results showing one representative
retainer trace for each cluster of leaked objects.
Retainer traces: This is the result from
an example website,
the retainer trace is an object reference chain from the GC root to a leaked
object. The trace shows why and how a leaked object is still kept alive in
memory. Breaking the reference chain means the leaked object will no longer
be reachable from the GC root, and therefore can be garbage collected.
By following the leak trace one step at a time, you will be able to find
a reference that should be set to null (but it wasn't due to a bug).
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 [8.3MB]
--8 (element)---> [InternalNode] (native) @130980288 [8.3MB]
--1 (element)---> [EventListener] (native) @131009888 [8.3MB]
--1 (element)---> [V8EventListener] (native) @224808192 [8.3MB]
--1 (element)---> [eventHandler] (closure) @168079 [8.3MB]
--context (internal)---> [<function scope>] (object) @181905 [8.3MB]
--bigArray (variable)---> [Array] (object) @182925 [8.3MB]
--elements (internal)---> [(object elements)] (array) @182929 [8.3MB]
...
To get a readable trace, the website under test needs to serve non-minified code (or at least minified code
with readable variable, function, and property names on objects).