staff-engineering-skills-memory-leaks
Installation
SKILL.md
Memory Leaks Trap
It works fine in testing. After a week in production, the OOM killer visits. Before writing any code that accumulates state, ask: what removes entries from this, and what limits its size?
How Memory Leaks Happen in GC Languages
In JavaScript and Go, leaks aren't about forgetting free(). They're about holding references you no longer need. The GC only reclaims unreachable memory; a reference held through a Map, closure, listener, or goroutine pins that memory forever.
The danger is the time dimension. A 200-byte-per-request leak is invisible in a 100-request test. At 1,000 req/s, it's 17GB per day.
The Five Leak Patterns
| Pattern | What happens | How to spot it |
|---|---|---|
| Unbounded accumulator | Map/Set/Array grows without eviction | Module-level collection with .set()/.push() but no .delete()/.pop() |
| Event listener leak | New listener per request, never removed | .on()/addEventListener without matching .off()/removeEventListener |
| Closure capture | Callback pins a large object in scope | Closure on a long-lived callback referencing outer-scope variables |
| Timer leak | setInterval runs forever |
No clearInterval on shutdown or when the resource is gone |
| Goroutine leak (Go) | Goroutine blocks on channel/lock forever | go func() without context cancellation or channel close |