46. Memory on a long-running service grows until it restarts every few days. How do you find the leak?
HardDebugging & production
Technical
Show model answer
Confirm it is a leak (memory grows with time or traffic and never drops after garbage collection) rather than a cache warming up. Take heap snapshots at two points and compare which object types grow and what retains them.
Typical culprits: unbounded caches or maps keyed by request data, listeners or timers that are never removed, global arrays that collect history, and closures holding large objects. Fix by bounding caches (LRU with a size limit), removing listeners, and adding a memory metric with an alert.