---
title: "MemLab: An open source framework for finding JavaScript memory leaks"
description: "MemLab finds JavaScript memory leaks by driving a headless browser with Puppeteer through a navigate-away/target/return sequence, then diffing heap snapshots as (SB \\ SA) ∩ SA' to find objects that should have been freed."
url: "https://swe.quest/articles/memlab-an-open-source-framework-for-finding-javascript-memory-leaks-d413135b7aeb2d8e"
canonical: "https://engineering.fb.com/2022/09/12/open-source/memlab/"
source: "Meta Engineering"
published: "2022-09-12"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 11
tags: ["memory-management","javascript","frontend","react","debugging"]
---

# MemLab: An open source framework for finding JavaScript memory leaks

A post on [Meta Engineering](https://swe.quest/sources/meta.md), published 2022-09-12, 11 min read, Deep dive. Original: [https://engineering.fb.com/2022/09/12/open-source/memlab/](https://engineering.fb.com/2022/09/12/open-source/memlab/)

## Summary

MemLab finds JavaScript memory leaks by driving a headless browser with Puppeteer through a navigate-away/target/return sequence, then diffing heap snapshots as (SB \\ SA) ∩ SA' to find objects that should have been freed. It filters candidates with framework knowledge such as detached React Fiber nodes, then generates and clusters retainer traces from GC roots. A lazily constructed graph-view API supports custom leak detectors, Jest memory assertions and heap analysis. At Meta it helped cut Facebook.com OOM crashes by 50%, React 18's aggressive Fiber cleanup on unmount cut average memory by nearly 25%, and interning Relay cache-key strings cut p99 memory by 20%.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Memory management](https://swe.quest/tags/memory-management.md) (Compilers & runtimes)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)
- [Frontend](https://swe.quest/tags/frontend.md) (Web & mobile)
- [React](https://swe.quest/tags/react.md) (Web & mobile)
- [Debugging](https://swe.quest/tags/debugging.md) (Engineering practices)

## Prerequisites

- JavaScript garbage collection ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))
- Chrome DevTools heap snapshots ([easy posts on Browsers](https://swe.quest/tags/browsers.md?difficulty=easy))
- React component lifecycle ([easy posts on React](https://swe.quest/tags/react.md?difficulty=easy))

## Keywords

MemLab, Puppeteer, V8, React Fiber, Relay, Jest, Hermes

## Related posts

- [Debugging JavaScript Memory Leaks](https://swe.quest/articles/debugging-javascript-memory-leaks-440c20d303c4be9c.md): Bun · 2025-04-02 · Medium · 8 min read · Memory management, Debugging, JavaScript, Runtimes & VMs
  Bun implements V8's writeHeapSnapshot API, so heap snapshots can be loaded and diffed in Chrome DevTools, where a steadily growing Delta column reveals leaks. bun:jsc's heapStats also reports per-type object counts, including objects protected from GC.
- [Bun 1.4](https://swe.quest/articles/bun-1-4-fea28913dacb5d89.md): Bun · 2026-08-20 · Medium · 217 min read · Runtimes & VMs, JavaScript, Performance engineering, Memory management, Rust
  Bun 1.4 adds 1,517 newly passing Node.js test-suite tests, fixes over 2,900 issues, and rewrites Bun from Zig to Rust.
- [Bun v1.0.20](https://swe.quest/articles/bun-v1-0-20-4c5d451d499e769b.md): Bun · 2023-12-24 · Medium · 6 min read · JavaScript, Runtimes & VMs, Memory management, Performance engineering
  Bun v1.0.20 cuts memory usage in node:fs async operations by avoiding redundant cross-thread string clones.
- [Bun v0.6.9](https://swe.quest/articles/bun-v0-6-9-0635261452349fca.md): Bun · 2023-06-13 · Medium · 3 min read · JavaScript, Runtimes & VMs, Memory management
  Bun v0.6.9 focuses on memory reductions: zero-copy string Response bodies in Bun.serve() and Response (60 MB vs Deno's 425 MB and Node's 1414 MB after 1000 responses of a 12 MB string), 50% less memory for cold bun install, and fixed leaks when importing modules.
- [OpenTelemetry for JavaScript Observability at Zalando](https://swe.quest/articles/opentelemetry-for-javascript-observability-at-zalando-001cdd3c281fae3c.md): Zalando Engineering · 2024-07-28 · Medium · 11 min read · Observability, JavaScript, Frontend, Web performance
  Zalando built thin OpenTelemetry-based observability SDKs for Node.js and the browser, sharing a common API package so isomorphic apps can be instrumented consistently.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
