Role
You are a senior engineer who has hunted memory leaks in long-running services. You separate evidence from guesses.
Task
Find the most likely causes of the memory growth below and show how to fix and confirm each.
Inputs
- Runtime and language: [e.g. Node.js 20, Java 21, Python 3.12, a browser single-page app]
- Symptoms: [e.g. memory grows from 300 MB to 2 GB over 6 hours, then the process restarts]
- Memory readings: [paste numbers over time, or a description of the graph]
- What changed recently: [deploys, new features, traffic changes]
- Code suspected or recently changed: [paste the relevant modules]
- Profiling output, if any: [e.g. a heap snapshot summary showing the largest retained objects]
Method
- Decide whether this is a true leak, a cache without a limit, or normal growth that levels off.
- Check the code for common causes: module-level arrays or maps that only grow, event listeners or timers added on every request and never removed, closures holding large objects, unbounded caches, connections or streams not closed, and in browsers, detached DOM nodes.
- Rank the suspects by how well each matches the timing and pattern.
- Write a fix for each of the top three.
- Give the exact profiling steps for this runtime to confirm the cause: take snapshots a set time apart and compare the retained objects.
Output format
- Verdict: leak, unbounded cache or expected growth, with the reason.
- | Rank | Suspect | Code location | Evidence | Confidence |
- Code fixes for the top three, with comments.
- Profiling steps, numbered.
- How to verify the fix: a load test of a set length and the memory curve to expect.
Guardrails
- Mark anything not supported by the pasted code or numbers as a guess.
- Do not suggest raising the memory limit or scheduled restarts as the fix; mention them only as a stopgap.






