Recall & Review
beginner
What is garbage collection in Node.js?
Garbage collection is the automatic process where Node.js frees up memory by removing objects that are no longer needed or referenced in the program.
Click to reveal answer
beginner
Why should you avoid global variables in Node.js for memory management?
Global variables stay in memory for the lifetime of the application, which can cause memory to be used unnecessarily and lead to memory leaks.
Click to reveal answer
intermediate
How can you detect memory leaks in a Node.js application?
You can use tools like Chrome DevTools, Node.js built-in inspector, or third-party modules to monitor memory usage and find objects that keep growing without being released.
Click to reveal answer
intermediate
What is the benefit of using streams in Node.js for memory management?
Streams process data in small chunks instead of loading everything into memory at once, which reduces memory usage and improves performance.
Click to reveal answer
intermediate
Explain the role of the 'heap' and 'stack' in Node.js memory management.
The stack stores simple, short-lived data like function calls and variables, while the heap stores objects and data that can grow dynamically. Efficient use of both helps manage memory well.
Click to reveal answer
Which of the following helps prevent memory leaks in Node.js?
✗ Incorrect
Avoiding global variables helps prevent memory leaks because globals stay in memory for the app's lifetime.
What Node.js feature processes data in chunks to save memory?
✗ Incorrect
Streams handle data in small parts, reducing memory use compared to loading all data at once.
Which tool can you use to inspect memory usage in Node.js?
✗ Incorrect
Chrome DevTools can connect to Node.js to inspect memory and debug leaks.
What does garbage collection do in Node.js?
✗ Incorrect
Garbage collection automatically frees memory that is no longer used.
Where are objects stored in Node.js memory?
✗ Incorrect
Objects are stored in the heap, which handles dynamic memory allocation.
Describe three best practices to manage memory effectively in a Node.js application.
Think about how to keep memory usage low and detect problems early.
You got /3 concepts.
Explain how garbage collection works and why it is important in Node.js.
Consider how Node.js cleans up memory without programmer intervention.
You got /3 concepts.