Skip to main content
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

1
Open the finding and choose Show how to find the leak, or open the leak guide from Memory.
2
Pick your runtime if it is not already selected.
3
Follow the numbered steps.
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

You have a heap profile or snapshot that points at the objects that keep growing.

Restarts and alerts

StackShift restarts a service that stops and tells you when it runs out of memory or keeps crashing. Nothing fails quietly.

Change memory

Pick a memory size for a service. StackShift marks the size that fits what it measured and shows the price difference.

What to improve

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.