Skip to content

facebook/memlab

⭐ 4,964  ·  #7  ·  JavaScript

A framework for finding JavaScript memory leaks and analyzing heap snapshots

JavaScript detector e2e facebook Memory

Project Analysis

🎯 PositioningPersistent Memory System
💡 Core ValueSolves the problem of AI Agents starting from scratch in every conversation. By using file storage, databases, or vector retrieval, it enables agents to have cross-session persistent memory, remembering user preferences, project context, and historical decisions.
👥 Target AudienceDevelopers who need agents to maintain long-term context, such as in project management or large codebase familiarization scenarios.

Why It's Worth Attention

4,964 Stars, in a rapid growth phase, worth early attention. Developed using JavaScript.

An automated framework for locating JavaScript memory leaks and analyzing heap snapshots.

Core Features

  • Automated Leak Detection: Automatically captures and compares heap snapshots through e2e test scenario replay, identifying objects not reclaimed by GC.
  • Deep Heap Snapshot Analysis: Provides structured APIs (e.g., HeapAnalysis) to traverse V8/Hermes heap graphs, supporting custom queries to match leak patterns.
  • Browser & Node.js Dual Support: Can interface with Puppeteer/Playwright to drive Chrome, or directly analyze Node.js process heaps.
  • Hermes Engine Compatibility: Optimized for React Native's Hermes engine, supporting its heap snapshot format.
  • Visualization & Export: Generates retention path graphs for leaked objects, supports JSON format snapshot export for secondary analysis.

Technical Architecture

  • Language & Runtime: Pure TypeScript/JavaScript implementation, relies on Node.js for core analysis logic.
  • Heap Processing Engine: Builds a memory graph model based on the V8 heap snapshot protocol (.heapsnapshot) and Hermes snapshot format.
  • Code Structure Highlights:
    • Modular analysis pipeline: SnapshotHeapNodeEdgeAnalyzer, supports plugin-based custom analyzers.
    • Test-driven design: Built-in memlab test command couples leak detection with E2E testing workflows.
    • CLI & API Separation: Provides the memlab command-line tool and the programmatic memlab npm package.

Quick Start Guide

bash
# Installation
npm install -g memlab

# Run leak detection on a specified URL (automatically opens browser)
memlab test --scenario "https://example.com"

# Analyze a local heap snapshot
memlab analyze /path/to/heap.heapsnapshot

# Programmatic usage (Node.js)
import { takeHeapSnapshot, diffHeapSnapshots } from 'memlab';
const snap1 = takeHeapSnapshot();
// ... perform actions ...
const snap2 = takeHeapSnapshot();
const leaks = diffHeapSnapshots(snap1, snap2);

Strengths, Weaknesses, and Use Cases

Strengths:

  • High automation: No need for manual heap snapshot recording; integrates with E2E tests for continuous monitoring.
  • Deep analysis: Supports custom object matching rules, can detect complex leaks like closures and DOM references.
  • Community backing: Maintained by Facebook/Meta, deeply integrated with the React Native ecosystem.

Weaknesses:

  • Learning curve: Requires understanding V8 heap graph concepts (nodes, edges, retention paths), not intuitive.
  • Performance overhead: Analysis of large heap snapshots (>500MB) is time-consuming, unsuitable for real-time online monitoring.
  • Platform limitations: Only supports V8 and Hermes engines, cannot be used with JSC or other JS engines.

Use Cases:

  • Frontend teams: Memory leak troubleshooting in React/React Native applications.
  • Performance engineers: Embedding memory regression detection in E2E test pipelines.
  • Node.js backend: Heap analysis for long-running services (e.g., microservices).

Community & Popularity

  • Stars: 4,964 (as of May 2026), showing steady growth, a leading tool in the memory analysis space.
  • Forks: ~300+, active contributors are primarily Meta internal developers, with fewer external PRs.
  • Recent Updates: Commits still present in May 2026 (e.g., Hermes snapshot compatibility fixes), but the core API has not seen major changes since 2024, indicating maturity and stability.
  • Issues: ~100+ open, mainly feature requests and Hermes-specific issues, with moderate response time (1-2 weeks).

Technical Information

  • 💻 Language: JavaScript
  • 📂 Topics: detector, e2e, facebook, heap, hermes
  • 🕐 Updated: 2026-01-16
  • 🔗 Visit GitHub Repository

Data updated on 2026-05-09 · Star count based on actual GitHub data

Project data from GitHub API, updated in real-time