본문으로 건너뛰기
Skillpedia
일반 코딩5.1k · #15056

memlab-capture-heap-snapshots

하는 일

한 번의 스냅샷이나 반복 동작에서 무엇이 늘어나는지 보여 주는 일련의 스냅샷을 찍는 방법을 설명합니다. 누수를 추적하려고 메모리 데이터가 필요한 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓브라우저 탭이나 Node.js 프로세스의 힙 스냅샷이 필요할 때.
  • ✓같은 상호작용을 반복한 뒤 메모리가 늘어나는지 보고 싶을 때.
  • ✓프로세스가 메모리 부족에 가까워서 덤프가 필요할 때.

스킬 링크

https://github.com/meta/memlab/blob/main/plugins/memlab/skills/memlab-capture-heap-snapshots/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/meta/memlab/blob/main/plugins/memlab/skills/memlab-capture-heap-snapshots/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“설정 대화 상자를 다섯 번 열기 전과 후에 제 웹 앱의 힙 스냅샷을 찍어서 비교할 수 있게 해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트가 단일 스냅샷이나 일련의 스냅샷을 고르고, 캡처할 브라우저나 프로세스를 설정한 뒤 파일을 저장합니다. 메모리 증가를 측정할 수 있도록 중간에 새로고침하지 않고 각 스냅샷을 찍습니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

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 run kill -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, open chrome://inspect, and use the Memory tab as in a browser.
  • In a memlab test: dumpNodeHeapSnapshot() from @memlab/core writes 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 --inspect and attach from chrome://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

  1. Load the page or start the process. Run the interaction a few times to warm up caches and lazy-loaded code.
  2. Take snapshot 0.
  3. Repeat the interaction N times (for example 10), returning to the starting state each time. Take the next snapshot. Do this 3–5 times.
  4. 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.
  5. 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

자주 묻는 질문

왜 여러 스냅샷을 찍나요?

한 스냅샷은 메모리에 무엇이 있는지 보여 주지만, 증가는 같은 세션에서 찍은 스냅샷을 비교해야 드러납니다.

어떤 빌드를 스냅샷으로 찍어야 하나요?

문제에 맞는 빌드를 쓰세요. 개발 빌드는 운영 빌드에 없는 추가 메모리를 담고 있습니다.

Chrome에서 직접 스냅샷을 찍을 수 있나요?

네. 스킬은 DevTools의 메모리 탭에서 스냅샷을 찍고 저장하는 단계를 설명합니다.

상세 정보

작성자의 원본 설명

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

인기도

GitHub 스타
5.1k
순위
#15056
라이선스
MIT
업데이트
2026. 10. 31.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬