memlab-find-web-leaks
하는 일
페이지를 열고, 상호작용 하나를 실행하고, 되돌리고, 메모리에 남은 객체를 보고하는 memlab 시나리오를 작성합니다. 모달, 대화 상자, 라우트, 사용자 흐름의 누수를 확인해야 하는 웹 개발자를 위한 스킬입니다.
사용하는 경우
- ✓페이지나 대화 상자에 메모리 누수가 있는지 확인하고 싶을 때.
- ✓사용자 흐름을 실행할 때마다 메모리가 늘어나는 것 같을 때.
- ✓객체를 살려 두는 코드를 가리키는 누수 보고서를 원할 때.
스킬 링크
https://github.com/meta/memlab/blob/main/plugins/memlab/skills/memlab-find-web-leaks/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“제 React 앱에서 설정 대화 상자를 열고 닫을 때 메모리가 새는지 확인하고, 누수가 있으면 고쳐 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
에이전트가 페이지, 동작, 정확한 되돌리기 단계가 있는 시나리오를 작성한 뒤 memlab을 실행합니다. 묶여서 나온 누수 추적 결과를 읽고, 분리된 DOM이나 마운트 해제된 React 컴포넌트를 붙잡는 코드를 고칩니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
Find memory leaks in a web app with memlab
memlab loads the page, takes a heap snapshot, runs the interaction you suspect
(action), undoes it (back), and takes two more snapshots. Objects that
action allocated and that are still alive after back are leak candidates.
By default memlab reports detached DOM elements and unmounted React Fiber
nodes, grouped into clusters by retainer trace.
1. Install
npm install -g memlab # or prefix every command with npx: npx memlab run ...
memlab version
2. Write the scenario
Save a file such as scenario.js. Pick one interaction, and make back
its exact inverse:
// scenario.js
module.exports = {
// Page to load first. memlab takes the baseline snapshot here.
url: () => 'http://localhost:3000/',
// The interaction suspected of leaking. Target snapshot after this.
action: async page => {
await page.click('[data-testid="open-settings"]');
await page.waitForSelector('[data-testid="settings-dialog"]');
},
// Undo the interaction without reloading. Final snapshot after this.
back: async page => {
await page.click('[data-testid="close-settings"]');
await page.waitForSelector('[data-testid="settings-dialog"]', {hidden: true});
},
};
Rules that keep the result valid:
- No reloads in
actionorback.page.goto(),page.reload(),location.reload()or a link that does a full page load start a new heap. memlab detects this and stops with "The page is reloaded. MemLab cannot analyze heap across page reloads." Client-side route changes are fine. backmust really undoaction. If the dialog stays open, its objects are still in use and nothing is reported (or everything is).pageis a PuppeteerPage. memlab 2.x uses Puppeteer 24: only use methods from the Puppeteer API.page.waitForXPath()no longer exists. Puppeteer locators have nocount()orfirst(); usepage.$$(selector)to count elements.awaitevery Puppeteer call.- Log in with
cookies(or insetup), not inaction. Work done inactionthatbackdoesn't undo shows up as leaks. - Keep it minimal. Add other callbacks only when needed.
repeatis only for stress tests.
All scenario callbacks, with examples, are in references/scenario-api.md.
3. Run
memlab run --scenario scenario.js
When it fails or gets stuck, add --verbose for stack traces, --headful to
watch the browser, or --debug to pause after each step. Leave them off
otherwise. --work-dir <dir> saves the run somewhere other than the default
working directory (memlab get-default-work-dir).
4. Read the result
MemLab found 1 leak(s)
--Similar leaks in this run: 4--
--Retained size of leaked objects: 8.3MB--
[Window] (native) @35847 [8.3MB]
--20 (element)---> [InternalNode] (native) @130981728 [8.3MB]
--1 (element)---> [EventListener] (native) @131009888 [8.3MB]
--1 (element)---> [V8EventListener] (native) @224808192 [8.3MB]
--1 (element)---> [eventHandler] (closure) @168079 [8.3MB]
--context (internal)---> [<function scope>] (object) @181905 [8.3MB]
--bigArray (variable)---> [Array] (object) @182925 [8.3MB]
- Each block is a cluster of leaks with similar retainer traces, sorted by retained size. "Similar leaks" is how many leaked objects share it.
- A trace starts at a GC root and ends at the leaked object. Each line is
--edge (edge type)---> [node name] (node type) @id [retained size]. - Find the link to break: scan for the first names that come from the
app (a closure, property or variable name) rather than the browser or the
framework. Above, the
eventHandlerclosure is still registered as an event listener, and its scope holdsbigArray. The fix is to remove the listener when the UI closes. - Traces are much easier to read when the app serves unminified code or keeps readable names.
- The text report is saved in the working directory as
data/out/leaks.txt.memlab runalso copies it todata/cur/leaks.txt, next to the three snapshotss1–s3.heapsnapshot. Runs through@memlab/apileave it only indata/out/.
5. When the trace isn't enough
memlab trace --node-id <id>: the retainer trace for one object.memlab view-heap --snapshot <file>: interactive heap browser.- Nothing reported but memory still grows? The built-in detector
자주 묻는 질문
되돌리기 단계는 왜 정확해야 하나요?
되돌리기 단계는 동작을 정확히 뒤집어야 하며, 그래야 그 뒤에도 살아 있는 객체를 누수로 판단할 수 있습니다.
시나리오가 페이지를 새로고침하나요?
아니요. 동작이나 되돌리기 단계에서 페이지를 새로고침하지 말라고 스킬이 말합니다.
기본적으로 어떤 객체를 보고하나요?
분리된 DOM 요소와 마운트 해제된 React 컴포넌트입니다.
상세 정보
작성자의 원본 설명
Find memory leaks in a web app with memlab. Write a test scenario (url, action, back) that drives the page in Chromium through Puppeteer, run `memlab run`, read the clustered leak traces, and fix the code that keeps detached DOM elements, unmounted React components or other objects alive. Use when the user asks to check a page, component, modal, dialog, route or user flow for memory leaks, to write a memlab scenario, to set up memory leak tests for a web app, or to find out why memory is not released after a UI interaction is undone.
repo: meta/memlab
인기도
- GitHub 스타
- 5.1k
- 순위
- #15057
- 라이선스
- MIT
- 업데이트
- 2026. 10. 31.
댓글
- …
이 저장소의 다른 스킬
memlab-analyze-heap-snapshot
5.1k에이전트가 힙 스냅샷을 분석해 JavaScript 앱의 메모리 누수를 찾고, 무엇이 객체를 살아 있게 하는지 설명하도록 돕습니다.
memlab-capture-heap-snapshots
5.1k에이전트가 브라우저, Node.js, Electron, React Native에서 JavaScript 힙 스냅샷을 찍도록 안내해, 메모리 사용을 분석할 수 있게 합니다.
memlab-memory-tests
5.1k에이전트가 메모리 누수를 잡아내는 자동 테스트를 작성하도록 돕습니다. Node.js 코드나 지속적 통합에서 실행되는 브라우저 흐름이 대상입니다.
비슷한 스킬
test-driven-development
311k에이전트가 기능이나 수정을 만들기 전에 실패하는 테스트를 먼저 쓰고, 그것을 통과시키는 가장 작은 코드를 작성하도록 가르칩니다.
verification-before-completion
311k에이전트가 작업, 수정, 빌드가 완료되었거나 통과했다고 말하기 전에 실제 점검을 실행하고 결과를 읽도록 가르칩니다.
migrate-to-shoehorn
310k테스트 파일의 위험한 타입 캐스팅을 shoehorn 라이브러리로 바꿔, 테스트가 일부 데이터만 써도 타입 검사를 통과하도록 돕습니다.