Node.js FAQ: Top Questions
32. How do you detect memory leaks in Node.js?
Memory leaks in Node.js occur when objects are unintentionally retained in memory, causing increased memory usage. Detection involves monitoring, profiling, and analyzing heap snapshots.
-
Tools:
--inspect
with Chrome DevTools,heapdump
,clinic.js
. - Signs: Growing RSS, frequent GC pauses, crashes.
- Techniques: Take heap snapshots, identify retained objects, check event listeners.
- Use Case: Optimizing long-running applications.