wowprompt

Memory leak diagnosis from growing memory use and pasted code

Works through the symptoms, memory readings and code of a service whose memory keeps climbing, names the most likely leak sources and gives the fix and a way to prove it worked. Use it when a server, worker or browser app slows down over hours and only a restart helps.

A ranked list of likely leak sources with evidence, code fixes for the top suspects, profiling steps to confirm, and a before and after check
The output this prompt produced, unedited.

The prompt

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

  1. Decide whether this is a true leak, a cache without a limit, or normal growth that levels off.
  2. 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.
  3. Rank the suspects by how well each matches the timing and pattern.
  4. Write a fix for each of the top three.
  5. 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

  1. Verdict: leak, unbounded cache or expected growth, with the reason.
  2. | Rank | Suspect | Code location | Evidence | Confidence |
  3. Code fixes for the top three, with comments.
  4. Profiling steps, numbered.
  5. 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.
memory leakmemory profilingheap snapshotperformance debuggingnode memorygarbage collection

How to run this

Copy the prompt and paste it into Gemini, then set the aspect ratio to 3:4. No reference photo is needed for this one.

The prompt is written in Markdown with each part under its own heading, which is what the copy action hands over. Change one section at a time, keeping the rest intact, so you can tell which change did the work.

Related prompts

All productivity