JavaScript · Senior · Question 10 of 75
Which scenario typically causes a memory leak in an SPA?
- ✓Correct answer: Handlers on
windowand timers that aren't removed when leaving the page - 2Using
constinstead ofletfor large arrays in functions - 3Frequently creating short-lived objects inside loops
Explanation
A subscription holds a closure, and through it the component's data and DOM nodes. Other sources: detached DOM nodes referenced from JS, growing global caches, forgotten setIntervals. Short-lived objects are efficiently collected by the GC's young generation. Leaks are found with Memory snapshots in DevTools.