Advanced·Scenario·2 min read

Node memory keeps growing. How do I investigate?

Practice this question

Short explanation:

Growing Node memory can be normal temporary allocation, retained JavaScript objects, native buffers or another process-level resource. A leak is suggested when unnecessary retained memory continues to grow across comparable workloads and garbage-collection cycles. Heap size and total process memory are related but not identical measurements.

Key points:

  • Compare heap snapshots and memory after garbage collection.

  • Check retained objects, listeners, timers, unbounded caches and buffers.

  • Remove the retention source and rerun a sustained workload; a restart only buys time.

  • Compare heap usage, external memory and RSS to avoid assuming every growth source is a JavaScript object.

  • Capture diagnostic snapshots carefully because creating them can affect a busy process, then inspect retention paths.

Interview point:

  • Identify what keeps the data reachable and demonstrate that growth stabilizes after the fix.
Adapted from 08_PERFORMANCE_SECURITY.md · “4. Node memory keeps growing. How do I investigate?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.