Diagnose Steadily Growing Memory Use From Heap Snapshots, Allocation Profiles, and the Deploy Timeline
You are helping me find the cause of a process whose memory use grows over time. I will give you evidence; your job is to reason from it, rank the likely causes, and propose the cheapest next experiment. Do not guess a fix before the evidence supports one. First, classify the growth from what I provide: - Is it a leak (memory that is still reachable but never needed), unbounded caching, fragmentation or allocator behavior (resident memory grows while live objects do not), or simply a bigger working set after a change? - Does the growth correlate with time, request count, a specific endpoint, a specific tenant, or a deploy? Say which correlation the data supports and which it cannot distinguish. Second, read the heap or allocation data. For each of the top growing types or call sites, tell me: what retains it (the path to the root), who allocates it, and whether it should have a bounded lifetime. Look specifically for unbounded maps and caches without eviction, listeners or callbacks registered per request and never removed, per-request objects captured by long-lived closures, buffers or streams not closed on error paths, and metrics label sets or log context that grow with user input. Third, compare against the deploy and configuration timeline: what changed shortly before the slope changed? Output exactly these sections: 1. Classification (one paragraph, with the evidence for it and your confidence). 2. Ranked hypotheses (up to four). For each: the evidence for, the evidence against, and what would confirm or refute it. 3. Next experiment: the single cheapest measurement that separates the top two hypotheses, with the exact command or setting if you know it, and what result means what. 4. Containment: a safe stopgap such as a restart schedule or a cache cap, with its risks. Say "the data provided cannot tell" whenever that is true. --- When to use this: when a service's resident memory climbs between restarts, an out-of-memory kill recurs, or a heap dump is too large to read by eye. How to adapt it: paste the language and runtime (for example Node, JVM, Go, Python), the memory limit, and two or three snapshot summaries taken at different times, since a single snapshot rarely shows growth. Include the deploy history for the period. If you only have graphs, describe the slope and any step changes in words. Example input: "Python API, 2 GB limit, restarts every ~9 hours. Heap summaries at hour 1 and hour 6 show dict and str counts tripling, with most growth under a function that builds a per-user lookup table. Deploy on Tuesday added request-level memoization." Good output classifies this as unbounded caching, names the memoization as the leading hypothesis, tells me to log cache size per hour as the next experiment, and suggests a size-capped cache as containment.
Sign in to upvote this prompt.