agentleFS
codebygarvcodebygarv/Ai-skills/skills/development/memory-leak-detector/SKILL.md

memory-leak-detector

Skill26 starsChanged 4 months agoMITView on GitHub

Identifies unclosed handles, event listener accumulation, retain cycles, and heap memory leak patterns.

The file

Files
SKILL.md

Purpose

Detect and fix memory leaks, lingering closures, detached DOM trees, unbounded cache growth, and uncollected resources in Node.js, JavaScript, Python, Go, and mobile applications.

When to Use

  • Applications whose memory (RSS / Heap) steadily climbs until crashing with Out-Of-Memory (OOM) errors.
  • Investigating heap profile snapshots and GC thrashing.
  • Reviewing caching layers, WebSocket connection registries, and event listeners.

What to Analyze

  1. Unbounded In-Memory Collections: Global arrays/maps that append data without TTL, LRU eviction, or size caps.
  2. Lingering Event Listeners / Subscriptions: Attaching listeners on recurring objects without matching removeEventListener / unsubscribe.
  3. Closure Scope Retention: Outer scope variables captured unintentionally by long-lived closures or callbacks.
  4. Unclosed System Handles: Database connections, file descriptors, streams, or timers (setInterval) left running.
  5. Detached DOM Nodes: In frontend SPAs, keeping JS object references to HTML elements removed from the document.

Output Format

  • Leak Mechanism: Detailed explanation of why the garbage collector cannot free the allocated memory.
  • Code Offender: Exact snippet causing the retention.
  • Fixed Implementation: Leak-free pattern (using WeakMap, LRU caches, cleanup hooks, or AbortController).
  • Heap Verification Guide: How to verify the fix via heap snapshots or profiling tools.

Avoid

  • Band-aid solutions like restarting pods every 2 hours without fixing the leak.
  • Using plain Javascript Map or Object as unbounded global caches.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.