memlab-analyze-heap-snapshot
Skill này làm gì
Skill này dùng công cụ memlab để đọc heap snapshot từ Chrome, Node.js, Electron hoặc React Native và truy vết vì sao bộ nhớ cứ tăng. Skill dành cho lập trình viên đang tìm vấn đề bộ nhớ hoặc sự cố crash trong ứng dụng JavaScript.
Khi nào nên dùng
- ✓Khi bạn có một tệp heap snapshot và muốn biết cái gì đang chiếm bộ nhớ.
- ✓Khi bộ nhớ của ứng dụng JavaScript cứ tăng hoặc nó hết bộ nhớ.
- ✓Khi bạn nghi ngờ có phần tử DOM bị tách rời hoặc bộ nhớ đệm tăng dần trong ứng dụng trình duyệt.
Liên kết skill
https://github.com/meta/memlab/blob/main/plugins/memlab/skills/memlab-analyze-heap-snapshot/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Đây là app.heapsnapshot từ máy chủ Node của tôi. Tìm xem cái gì cứ tăng trong bộ nhớ và gợi ý cách sửa.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent tải snapshot vào memlab, chạy các công cụ chẩn đoán nhanh và điều tra, rồi truy vết chuỗi tham chiếu giữ các đối tượng tồn tại. Sau đó agent gợi ý cách sửa dựa trên các phát hiện đó.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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. Onecallruns several tools in one server session, so load the snapshot and analyze it in the same command: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
callstarts a new server and reloads the snapshot. For an investigation with many steps, keep one server running instead; see 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/memlabthenclaude plugin install memlab@memlab(Claude Code), orcodex plugin marketplace add meta/memlabthencodex plugin add memlab@memlab(Codex). For the server alone, give themclaude 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. Keep--max-old-space-size=8192or higher: without it, large snapshots are refused.
2. Get the snapshot
memlab_load_snapshottakes a local absolute path. If only<path>.gzexists, pass<path>and the server decompresses it. Download remote snapshots first.- For a file over about 1 GB, call
memlab_snapshot_headerfirst. It reads node and edge counts without parsing the graph and says whether the snapshot will load. - One snapshot shows what is in memory. To show what grows, you need two
or more snapshots taken from the same page or process while an interaction
repeats. If the user has none, see the
memlab-capture-heap-snapshotsskill or the memlab docs.
3. Triage
memlab_load_snapshotwith the path. Read the quick diagnosis it returns.- In parallel (all analysis tools are read-only once a snapshot is loaded):
memlab_quick_diagnosis: summary, top objects, class histogram, duplicated strings.memlab_auto_investigate: top retainers with retainer chains and severity, pinch points, unbounded caches, pending promises, known framework leak patterns.
memlab_app_heapto split the heap into application data, bundle source and engine internals before blaming the app for the total.- Note whether it is a browser or a Node.js heap; DOM tools only apply to browser snapshots.
4. Follow the matching path
Pick the path that fits the triage result. Each path is a short tool sequence in references/investigation-paths.md.
| Triage shows | Path |
|---|---|
| Many duplicated or huge strings | A: String waste |
| Detached DOM elements (browser) | B: DOM leaks |
| A class with very many instances, or one object retaining >5% of the heap | C: Object accumulation |
| Large closures in retainer chains | D: Closure leaks |
| Large non-built-in globals | E: Global variables |
| Many callback/listener/handler objects | F: Listener accumulation |
Many identical Error objects |
G: Repeated errors |
| Metric, cache key or record field with huge value cardinality | H: Cardinality explosion |
| Only one snapshot, need a growth guess | I: Single-snapshot growth signals |
| Three or more snapshots in order | J: Trend across snapshots |
| Huge detached tree in a browser snapshot, possibly from DevTools | K: Real leak or dev artifact |
5. Explain the retention
For the suspect object:
memlab_retainer_tracewith itsnode_id: the shortest path from a GC root. Useexpand: truewhen the interesting frame is hidden in an elided run.memlab_retainer_layerswith the samenode_idbefore proposing a fix. It lists every independent retaining path; cutting one edge frees nothing if another path still holds the object.memlab_closure_inspectionwhen a closure (or a suspended async function) is in the chain: it shows the captured variables and their s
Câu hỏi thường gặp
Tôi lấy heap snapshot ở đâu?
Một skill riêng bao gồm việc chụp chúng từ Chrome, Edge, Node.js, Electron hoặc React Native.
Nó có cần thiết lập đặc biệt không?
Skill có thể chạy memlab từ dòng lệnh bằng npx nếu các công cụ memlab không được thiết lập như một máy chủ.
Nó có giải thích vì sao một đối tượng vẫn nằm trong bộ nhớ không?
Có. Nó truy vết chuỗi tham chiếu đang giữ đối tượng đó tồn tại.
Chi tiết
Mô tả gốc của tác giả
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.
repo: meta/memlab
Độ phổ biến
- Sao GitHub
- 5.1k
- Vị trí xếp hạng
- #15055
- Giấy phép
- MIT
- Cập nhật
- 31/10/2026
Bình luận
- …
Thêm skill từ kho mã này
memlab-capture-heap-snapshots
5.1kHướng dẫn agent của bạn chụp heap snapshot JavaScript từ trình duyệt, Node.js, Electron hoặc React Native, để bạn có thể nghiên cứu mức dùng bộ nhớ.
memlab-find-web-leaks
5.1kGiúp agent của bạn tìm rò rỉ bộ nhớ trong trang web bằng cách chạy một bài kiểm thử tự động một tương tác và đọc các báo cáo rò rỉ được tạo ra.
memlab-memory-tests
5.1kGiúp agent của bạn viết các bài kiểm thử tự động để phát hiện rò rỉ bộ nhớ, cho mã Node.js hoặc cho luồng trình duyệt chạy trong tích hợp liên tục.
Skill tương tự
diffs
394kGiúp agent của bạn tạo một diff có thể chia sẻ về các chỉnh sửa, dưới dạng liên kết xem hoặc file ảnh, thay vì một bản tóm tắt viết tay.
coding-agent
394kGiúp agent của bạn giao một việc lập trình lớn cho Codex, Claude Code hoặc OpenCode chạy nền, rồi theo dõi tiến độ của nó.
gh-issues
394kGiúp agent của bạn tìm issue trên GitHub, chọn những issue cần xử lý và mở pull request với bản sửa, kể cả theo dõi nhận xét đánh giá.