> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackshift.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Find a memory leak

> When memory climbs and only drops on restart, use the leak guide for your runtime. Node.js can take a memory snapshot from the dashboard.

> [!TIP]
>
> **Live.** This area is documented as current, user-reliable behavior.

## Goal

Find what is growing in your app.

## Prerequisites

* A likely leak finding, or a service whose memory rises over hours.
* For snapshots, a Node.js service.

## Workflow

**Step 1**

Open the finding and choose Show how to find the leak, or open the leak guide from Memory.

**Step 2**

Pick your runtime if it is not already selected.

**Step 3**

Follow the numbered steps.

**Step 4**

Raising memory only buys time. It does not stop the climb.

## Node.js snapshots

* Choose Take memory snapshot. The service is paused briefly while the snapshot is written.
* The .heapsnapshot file appears under Your snapshots with its time and size. Choose Download.
* Snapshots are kept 7 days. Only project members can download them.
* Take one now and another after memory has grown, or choose Remind me in 1 hour. You get an in-app notice and an email.
* Open both in Chrome DevTools, Memory, load the files, and use Comparison to see which objects grew.
* This needs the snapshot flags that StackShift sets with the Node.js runtime cap. If you set NODE\_OPTIONS yourself, add --heapsnapshot-signal=SIGUSR2 --diagnostic-dir=/tmp.

## Go

* Import net/http/pprof and serve it on a private port.
* Fetch /debug/pprof/heap now and again later.
* Compare them with go tool pprof -base first.pb.gz second.pb.gz.
* Common causes: goroutines that never exit, maps and caches that never evict, and slices that keep a large backing array.

## Python

* Start tracemalloc and take a snapshot now and later.
* Compare them with snapshot.compare\_to and read the top differences by file and line.
* Common causes: module-level lists and dicts that only grow, unbounded caches, and objects kept in reference cycles.

## PHP

* Log memory\_get\_usage() at the start and end of a request or job.
* On long-running workers such as Octane or queue workers, restart a worker after a number of jobs or when memory passes a limit.
* Common causes: static arrays that collect data, query logs held in memory, and large result sets loaded at once. Use cursors or chunks.

## Java

* Take a heap dump with jcmd PID GC.heap\_dump /tmp/heap.hprof.
* Open it in Eclipse MAT or VisualVM and look at the dominator tree.
* Common causes: static collections, caches without a size limit, and listeners that are never removed.

## Ruby

* Use the memory\_profiler gem around a request or job, or ObjectSpace to count objects by class.
* Compare counts now and later.
* Common causes: constants and class variables that collect data, global caches, and large arrays built per request.

## Expected result

> [!TIP]
>
> You have a heap profile or snapshot that points at the objects that keep growing.

## Related guides

> [card] [Restarts and alerts](https://docs.stackshift.cloud/performance/never-silent.md)
>
> StackShift restarts a service that stops and tells you when it runs out of memory or keeps crashing. Nothing fails quietly.

> [card] [Change memory](https://docs.stackshift.cloud/performance/change-memory.md)
>
> Pick a memory size for a service. StackShift marks the size that fits what it measured and shows the price difference.

> [card] [What to improve](https://docs.stackshift.cloud/performance/what-to-improve.md)
>
> A ranked list of findings for the project. Each says what is wrong, shows the evidence, says what fixing it is worth and gives the steps.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.