Workflow Debugging

Debug a Memory Leak

Workflow for finding and fixing memory leaks

debuggingmemoryperformance
CLAUDE.md

When debugging a memory leak:

  1. Confirm the leak: monitor memory usage over time. A leak shows steadily increasing memory without plateauing.
  2. Take heap snapshots at intervals: before the operation, after repeating the operation several times.
  3. Compare snapshots to identify objects that accumulate but are never released.
  4. Check common causes: event listeners not removed, intervals/timers not cleared, closures holding references, growing caches without eviction, detached DOM nodes.
  5. Fix the leak: add cleanup functions, clear timers, remove event listeners, add cache size limits.
  6. Verify the fix by monitoring memory usage under the same load pattern.

Copy this workflow into your CLAUDE.md or agent config file so your agent follows this process automatically.

get crystl