मुख्य सामग्री पर जाएँ
Skillpedia
टेस्टिंग5.1k · #15057

memlab-find-web-leaks

यह क्या करती है

यह memlab परिदृश्य (scenario) लिखती है जो पेज खोलता है, एक इंटरैक्शन चलाता है, उसे पलटता है, और उन ऑब्जेक्ट की रिपोर्ट देता है जो मेमोरी में बचे रह जाते हैं। यह उन वेब डेवलपर्स के लिए है जिन्हें मॉडल, डायलॉग, रूट या यूज़र फ़्लो में लीक जाँचना है।

कब इस्तेमाल करें

  • ✓जब आप किसी पेज या डायलॉग में मेमोरी लीक जाँचना चाहते हैं।
  • ✓जब कोई यूज़र फ़्लो हर बार चलाने पर ज़्यादा मेमोरी लेता लगे।
  • ✓जब आपको ऐसी लीक रिपोर्ट चाहिए जो उस कोड की ओर इशारा करे जो ऑब्जेक्ट ज़िंदा रख रहा है।

Skill का लिंक

https://github.com/meta/memlab/blob/main/plugins/memlab/skills/memlab-find-web-leaks/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/meta/memlab/blob/main/plugins/memlab/skills/memlab-find-web-leaks/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“जाँचिए कि मेरे React ऐप में सेटिंग्स डायलॉग खोलने और बंद करने से मेमोरी लीक होती है या नहीं, और जो लीक मिले उसे ठीक कीजिए।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

आपका एजेंट एक परिदृश्य लिखता है जिसमें पेज, एक कार्रवाई और उसे ठीक से पलटने वाला चरण होता है, फिर memlab चलाता है। वह समूहित लीक ट्रेस पढ़ता है और उस कोड को ठीक करता है जो डिटैच्ड DOM या अनमाउंट हुए कंपोनेंट को ज़िंदा रख रहा है।

तकनीकी सामग्री (मूल 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 action or back. 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.
  • back must really undo action. If the dialog stays open, its objects are still in use and nothing is reported (or everything is).
  • page is a Puppeteer Page. memlab 2.x uses Puppeteer 24: only use methods from the Puppeteer API. page.waitForXPath() no longer exists. Puppeteer locators have no count() or first(); use page.$$(selector) to count elements.
  • await every Puppeteer call.
  • Log in with cookies (or in setup), not in action. Work done in action that back doesn't undo shows up as leaks.
  • Keep it minimal. Add other callbacks only when needed. repeat is 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 eventHandler closure is still registered as an event listener, and its scope holds bigArray. 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 run also copies it to data/cur/leaks.txt, next to the three snapshots s1–s3.heapsnapshot. Runs through @memlab/api leave it only in data/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
अपडेट की गई
31/10/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills