0
0
Node.jsframework~5 mins

Common memory leak patterns in Node.js - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a memory leak in Node.js?
A memory leak happens when a program keeps using more and more memory because it doesn't release memory it no longer needs. This can slow down or crash the app.
Click to reveal answer
beginner
How can global variables cause memory leaks?
Global variables stay in memory for the whole app life. If you store large data there and never clear it, memory keeps growing.
Click to reveal answer
intermediate
Why do event listeners cause memory leaks?
If you add event listeners but never remove them, they keep references to objects, so memory can't be freed.
Click to reveal answer
intermediate
What is a closure-related memory leak?
Closures keep references to variables even after the outer function finishes. If those variables hold big data and are not cleared, memory leaks happen.
Click to reveal answer
beginner
How can caching cause memory leaks?
If you cache data without limits or expiration, the cache grows forever, using more memory.
Click to reveal answer
Which of these is a common cause of memory leaks in Node.js?
ANot removing event listeners
BUsing async/await
CWriting synchronous code
DUsing console.log
What happens if you keep large objects in global variables?
AThey get garbage collected immediately
BThey cause syntax errors
CThey stay in memory for the app lifetime
DThey improve performance
How can closures lead to memory leaks?
ABy freeing memory too early
BBy keeping references to variables longer than needed
CBy causing syntax errors
DBy blocking event loops
What is a safe way to avoid cache-related memory leaks?
ASet limits or expiration on cache
BUse unlimited cache size
CNever use cache
DStore cache in global variables
Which tool can help find memory leaks in Node.js?
ANode.js debugger
Bconsole.log only
Cnpm install
DChrome DevTools heap profiler
Explain three common patterns that cause memory leaks in Node.js and how to avoid them.
Think about what keeps data in memory longer than needed.
You got /4 concepts.
    Describe how caching can lead to memory leaks and what strategies help prevent this.
    Consider what happens if cache never clears old data.
    You got /4 concepts.