Group
  • Performance

    Find and fix memory leaks in my app

    Hunt down the leaks that make pages slow over time and servers crash at 3am: listeners, timers, subscriptions, and unbounded growth.

    • Debug & fix
    • Improve quality
    • Advanced
    • General

Free Prompt

I want to find memory leaks before my users' browsers and my server find them for me. Audit both sides: Client-side, look for: 1. Event listeners added but never removed when components unmount or elements are removed. 2. Timers (setInterval, setTimeout chains) that keep running after their UI is gone. 3. Subscriptions (websockets, observers, store subscriptions) without unsubscribe paths. 4. Closures holding references to large objects or detached DOM nodes. 5. Client-side caches or arrays that only ever grow (every fetched item appended forever). Server-side, look for: 1. Module-level Maps, arrays, or caches with no eviction policy. These are the classic Node leak: memory climbs until the process dies. 2. Event emitter listener buildup (listeners added per request on a long-lived emitter). 3. Unclosed resources: database cursors, file handles, HTTP streams without cleanup on error paths. 4. Per-request data attached to long-lived objects. For each finding, implement the fix: remove listeners on teardown, clear timers, add eviction or size caps to caches, close resources in finally blocks. Where possible, verify: a before/after measurement or a small stress script showing memory stabilizing instead of climbing. If my platform makes profiling hard, at minimum show me the code-level fixes with reasoning.

What This Does / How This Helps

This audits your client and server code for the classic leak patterns (orphaned listeners, uncapped caches, unclosed resources) and fixes them with teardown logic and eviction caps. Memory leaks don't show up in development because you restart constantly and test for minutes at a time. In production they announce themselves as a server that crashes every three days or a page that gets sluggish the longer a user stays on it. The server-side unbounded Map is especially common in generated code, because 'just cache it in a module-level object' is the AI's favorite performance fix.

Want to skip doing this by hand?

Fortivibe audits your app for all of the areas these prompts cover (and more).

See What We Check

Related Prompts