# Heap Snapshot Analysis

Finds JavaScript memory leaks in heap snapshots and explains why objects stay alive.

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

## Install

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

## Description

Analyze JavaScript heap snapshots (.heapsnapshot files from Chrome, Edge, Node.js, Electron or React Native/Hermes) with memlab to find memory leaks, explain why objects stay in memory, and suggest fixes. Use when the user shares or mentions a heap snapshot, asks why memory or heap size keeps growing, sees an out-of-memory crash, detached DOM elements, a growing cache or listener count, or wants to compare snapshots taken before and after a change. Works through the memlab MCP server tools (memlab_*) or, without MCP, the memlab-cli command from the @memlab/mcp-server npm package.

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

# Analyze a JavaScript heap snapshot with memlab

memlab parses a V8 or Hermes heap snapshot into a queryable graph and answers
questions about it: what fills the heap, what keeps growing, and which chain of
references keeps an object alive.

## 1. Get the tools

- **MCP tools available** (names start with `memlab_`): use them directly.
- **No MCP tools**: use `memlab-cli`, which runs the same tools from a shell.
  One `call` runs several tools in one server session, so load the snapshot
  and analyze it in the same command:

  ```bash
  npx -y -p @memlab/mcp-server memlab-cli call \
    memlab_load_snapshot '{"file_path":"/abs/path/app.heapsnapshot"}' \
    memlab_quick_diagnosis '{}' \
    memlab_auto_investigate '{}'
  ```

  Each `call` starts a new server and reloads the snapshot. For an
  investigation with many steps, keep one server running instead; see
  [references/memlab-cli.md](references/memlab-cli.md).
- If the user wants the MCP server set up permanently, suggest the memlab
  plugin, which also installs these skills: `claude plugin marketplace add meta/memlab`
  then `claude plugin install memlab@memlab` (Claude Code), or
  `codex plugin marketplace add meta/memlab` then `codex plugin add memlab@memlab`
  (Codex). For the server alone, give them
  `claude mcp add memlab -e NODE_OPTIONS=--max-old-space-size=8192 -- npx -y -p @memlab/mcp-server memlab-mcp`
  (Claude Code) or the JSON config in the
  [MCP server docs](https://meta.github.io/memlab/docs/mcp-server). Keep
  `--max-old-space-size=8192` or higher: without it, large snapshots are refused.

## 2. Get the snapshot

The rest: https://github.com/meta/memlab/blob/HEAD/plugins/memlab/skills/memlab-analyze-heap-snapshot/SKILL.md
