🔍

Memory Leak Detector

Verified

by Community

Diagnoses memory leaks in applications with heap profiling techniques, common leak patterns by language, and systematic approaches to identifying and fixing memory growth.

systemmemorydebuggingperformanceprofilingleak

Memory Leak Detector

Find and fix memory leaks in applications using systematic profiling and analysis. Covers common leak patterns by language with specific detection tools and resolution strategies.

Usage

Describe the memory issue — growing memory usage, OOM kills, or suspected leak. Specify the language/runtime. The detector guides you through profiling, identifying the leak source, and implementing the fix.

Parameters

  • Language: Node.js, Python, Java, Go, or C/C++
  • Symptom: Gradual growth, Sudden spike, OOM kills, or Suspected but unconfirmed
  • Environment: Development, Staging, or Production (constraints differ)
  • Tool access: Full profiling tools, Limited (production), or None yet

Examples

  1. Node.js Heap Analysis: Use --inspect and Chrome DevTools to take heap snapshots, compare allocations between snapshots, and identify retained object trees causing growth in an Express server.
  1. Python Memory Profiling: Track memory usage with tracemalloc, identify the top allocation sources, find reference cycles preventing garbage collection, and use objgraph for visualization.
  1. Java GC Analysis: Analyze GC logs for increasing heap usage after full GC cycles, take heap dumps with jmap, analyze with Eclipse MAT, and identify dominator trees holding leaked objects.
  1. Production Memory Investigation: Safely profile a production Node.js process — enable heap profiling with minimal overhead, capture periodic snapshots, and analyze offline without impacting users.

Guidelines

  • Memory growth is confirmed with time-series monitoring before deep profiling begins
  • Common leak patterns are checked first: event listeners, caches without eviction, closures, global references
  • Heap snapshots are compared over time to identify growing object counts by constructor
  • Retained size vs. shallow size distinction identifies the actual impact of each leaked object
  • GC behavior is analyzed to distinguish leaks (post-GC growth) from normal allocation patterns
  • Language-specific tools are recommended: Chrome DevTools (Node), tracemalloc (Python), VisualVM (Java)
  • Production profiling uses sampling (low overhead) over instrumentation (high overhead)
  • Leak fixes are verified by monitoring memory over hours/days after deployment
  • Container memory limits provide a safety net while leaks are being investigated
  • Common architectural causes are addressed: unbounded caches, connection pools, event emitter accumulation