Recall & Review
beginner
What is a heap snapshot in Node.js?
A heap snapshot is a detailed record of the memory used by a Node.js application at a specific time. It shows all objects in memory and their relationships, helping to find memory leaks.
Click to reveal answer
beginner
How do you take a heap snapshot using Chrome DevTools with Node.js?
You start your Node.js app with the --inspect flag, open Chrome DevTools, connect to the Node process, go to the Memory tab, and click 'Take heap snapshot'.
Click to reveal answer
intermediate
Why are heap snapshots useful for finding memory leaks?
Heap snapshots show which objects stay in memory longer than expected. By comparing snapshots over time, you can spot objects that should be gone but are still kept, indicating leaks.
Click to reveal answer
intermediate
What does the 'Retainers' view in a heap snapshot show?
The 'Retainers' view shows what other objects are keeping a selected object in memory. This helps find why an object is not being removed and causing a memory leak.
Click to reveal answer
beginner
Name one common cause of memory leaks visible in heap snapshots.
One common cause is forgotten event listeners or timers that keep references to objects, preventing garbage collection.
Click to reveal answer
What flag do you use to enable debugging for heap snapshots in Node.js?
✗ Incorrect
The --inspect flag enables the Node.js process to be debugged and connected to Chrome DevTools for heap snapshots.
Which Chrome DevTools tab do you use to take a heap snapshot?
✗ Incorrect
The Memory tab in Chrome DevTools is used to take heap snapshots and analyze memory usage.
What does a heap snapshot NOT show?
✗ Incorrect
Heap snapshots focus on memory, not CPU usage.
If an object is still in memory but should be gone, what might this indicate?
✗ Incorrect
Objects that stay in memory unexpectedly often indicate a memory leak.
What is a common cause of memory leaks visible in heap snapshots?
✗ Incorrect
Forgotten event listeners keep references alive, causing memory leaks.
Explain how to take and use a heap snapshot to find memory leaks in a Node.js app.
Think about the steps from starting the app to analyzing objects in memory.
You got /7 concepts.
Describe what information a heap snapshot provides and why it is helpful for debugging memory issues.
Focus on what you see in the snapshot and how it helps find leaks.
You got /5 concepts.