memlab-capture-heap-snapshots
Skill này làm gì
Skill này giải thích cách chụp một snapshot đơn hoặc một chuỗi snapshot để thấy những gì tăng lên qua các thao tác lặp lại. Skill dành cho lập trình viên cần dữ liệu bộ nhớ để truy tìm rò rỉ.
Khi nào nên dùng
- ✓Khi bạn cần một heap snapshot của một tab trình duyệt hoặc tiến trình Node.js.
- ✓Khi bạn muốn xem bộ nhớ có tăng sau khi lặp lại một tương tác hay không.
- ✓Khi tiến trình của bạn gần hết bộ nhớ và bạn cần một bản dump.
Liên kết skill
https://github.com/meta/memlab/blob/main/plugins/memlab/skills/memlab-capture-heap-snapshots/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
“Chụp heap snapshot của ứng dụng web của tôi trước và sau khi mở hộp thoại cài đặt năm lần, để tôi so sánh chúng.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent chọn một snapshot đơn hoặc một chuỗi, thiết lập trình duyệt hoặc tiến trình để chụp, rồi lưu các tệp. Agent chụp từng snapshot mà không tải lại giữa chừng, để có thể đo mức tăng.
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.
Capture JavaScript heap snapshots
A heap snapshot is a full dump of a JavaScript heap: every object, the
references between them, and their sizes. memlab, Chrome DevTools and the
memlab MCP server all read the same .heapsnapshot format.
Decide what to capture first
- "What is using memory?" One snapshot, taken when memory is high.
- "Is something leaking?" Several snapshots from the same page or process: no reload and no restart in between, with the suspect interaction repeated between captures. A single snapshot can't show growth.
- Take snapshots from a build that matches the problem. Development builds (React development mode, hot reload, source-map tooling) hold extra memory a production build doesn't.
Browser (Chrome, Edge)
By hand: DevTools → Memory → Heap snapshot → Take snapshot, then right-click the snapshot → Save.... DevTools runs garbage collection before each snapshot. Use a profile without extensions (or a guest window): extensions add their own objects to the page's heap.
From an agent, with the memlab MCP server: start the browser with
--remote-debugging-port=9222 --user-data-dir=/tmp/chrome-memlab, then call
memlab_capture with out_dir and a label. Chrome 136 and later ignore
--remote-debugging-port on the default profile, so the separate
--user-data-dir is required; a fresh profile also has no extensions. It also captures the page's dedicated workers, which a page snapshot
never includes. list_targets: true lists the pages it can attach to, and
url_filter picks one. A saved capture can later be referred to as
checkpoint:<label> wherever a snapshot path is accepted.
From Puppeteer or Playwright test code (Chromium only): use a CDP session. See references/capture-code.md for a copy-paste helper that runs garbage collection and streams the snapshot to a file.
Node.js
- From code:
require('v8').writeHeapSnapshot()writes a snapshot into the current directory and returns the file name. Pass a path to choose it. - From outside, on demand: start with
node --heapsnapshot-signal=SIGUSR2 app.js, then runkill -USR2 <pid>each time you want a snapshot. - Just before running out of memory: start with
node --heapsnapshot-near-heap-limit=3 app.js(Node.js 14.18+/15.1+). It writes up to 3 snapshots as the heap approaches its limit. - Interactively: start with
node --inspect app.js, openchrome://inspect, and use the Memory tab as in a browser. - In a memlab test:
dumpNodeHeapSnapshot()from@memlab/corewrites a snapshot to a temp folder and returns its path.
Writing a snapshot pauses the process and can temporarily need about as much memory again as the heap itself. Don't take one from a production server that is already close to its memory limit unless you can afford the pause.
Electron
- Renderer processes: open DevTools in the window and use the Memory tab.
- Main process: it is Node.js, so use
v8.writeHeapSnapshot(), or start the app with--inspectand attach fromchrome://inspect.
React Native (Hermes)
Open the debugger for the app (React Native DevTools) and take a heap snapshot from its Memory panel. memlab reads Hermes snapshots too.
memlab itself
memlab run --scenario <file> and memlab snapshot --scenario <file> drive
a page in Chromium and save s1.heapsnapshot (baseline), s2.heapsnapshot
(after the action) and s3.heapsnapshot (after undoing it) under
$(memlab get-default-work-dir)/data/cur/. See the memlab-find-web-leaks
skill for writing the scenario.
Capture a series that shows growth
- Load the page or start the process. Run the interaction a few times to warm up caches and lazy-loaded code.
- Take snapshot 0.
- Repeat the interaction N times (for example 10), returning to the starting state each time. Take the next snapshot. Do this 3–5 times.
- Optional but valuable: leave the app idle for a minute, run GC, and take a final "settle" snapshot. Growth that disappears here was work in flight, not a leak.
- Name the files in order and record the cycle count, for example
rung_00_c000.heapsnapshot,rung_01_c010.heapsnapshot, ... memlab's series tools read the cycle count from that naming.
Then analyze them with memlab_sequence_analysis or memlab_leak_report
(paths in order), or diff two of them with memlab_diff_snapshots. The
memlab-analyze-heap-snapshot skill
Câu hỏi thường gặp
Vì sao phải chụp nhiều snapshot?
Một snapshot cho thấy những gì đang có trong bộ nhớ, nhưng mức tăng chỉ thấy khi so sánh các snapshot chụp trong cùng một phiên.
Nên chụp bản build nào?
Dùng bản build phù hợp với vấn đề, vì bản build phát triển giữ thêm bộ nhớ mà bản build production không giữ.
Tôi có thể tự chụp snapshot trong Chrome không?
Có. Skill giải thích các bước trong tab Memory của DevTools để chụp và lưu snapshot.
Chi tiết
Mô tả gốc của tác giả
Capture JavaScript heap snapshots (.heapsnapshot files) for memory analysis from Chrome or Edge, Puppeteer, Playwright, Node.js, Electron or React Native (Hermes), including a series of snapshots that shows what grows over repeated interactions. Use when the user needs a heap snapshot, a heap dump of a Node.js process or one taken near out-of-memory, wants to measure memory growth or a suspected leak, or asks how to take snapshots in a test so memlab can analyze them.
repo: meta/memlab
Độ phổ biến
- Sao GitHub
- 5.1k
- Vị trí xếp hạng
- #15056
- 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-analyze-heap-snapshot
5.1kGiúp agent của bạn tìm rò rỉ bộ nhớ trong ứng dụng JavaScript bằng cách phân tích heap snapshot và giải thích điều gì giữ các đối tượng tồn tại.
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á.