| name | memory-leak |
| description | Finds potential memory leaks - uncleaned listeners, unclosed connections, growing caches |
| argument-hint | ["file-path"] |
| user-invocable | true |
| allowed-tools | Read Grep Glob |
| effort | medium |
Memory Leak Analysis
Target: $1 (or src/ if not specified)
Pattern 1: Event Listeners Without Cleanup
useEffect(() => {
window.addEventListener('resize', handler)
}, [])
Pattern 2: Timers Not Cleared
setInterval(syncData, 5000)
const id = setInterval(syncData, 5000)
return () => clearInterval(id)
Pattern 3: Unbounded Caches
const cache = new Map()
cache.set(key, value)
Pattern 4: Unclosed DB/File Connections
Look for db.connect() without corresponding db.close() in error paths.
For each finding:
- Show the leaking code
- Explain what accumulates and why it matters
- Provide the fix
Rate by severity: Critical (crashes in production under load) / Warning (gradual degradation) / Minor (theoretical).