Memory leak

From berkcangumusisik/claude-code-practices · View interactive version

Memory leak is an AI agent skill from the GitHub repository berkcangumusisik/claude-code-practices. Finds potential memory leaks - uncleaned listeners, unclosed connections, growing caches

How to use this skill

Skill file

Memory Leak Analysis

Target: $1 (or src/ if not specified)

Pattern 1: Event Listeners Without Cleanup

// ❌ Listener added but never removed
useEffect(() => {
  window.addEventListener('resize', handler)
}, []) // Missing: return () => window.removeEventListener('resize', handler)

Pattern 2: Timers Not Cleared

// ❌ Interval runs forever
setInterval(syncData, 5000)

// ✅ Store ref and clear on unmount
const id = setInterval(syncData, 5000)
return () => clearInterval(id)

Pattern 3: Unbounded Caches

// ❌ Cache grows indefinitely
const cache = new Map()
cache.set(key, value) // never evicted

Pattern 4: Unclosed DB/File Connections

Look for db.connect() without corresponding db.close() in error paths.


For each finding:

  1. Show the leaking code
  2. Explain what accumulates and why it matters
  3. Provide the fix

Rate by severity: Critical (crashes in production under load) / Warning (gradual degradation) / Minor (theoretical).

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.