React · Senior · Question 19 of 75
Which of these scenarios causes a memory leak in a React app?
- ✓Correct answer: Subscribing to
windowor a WebSocket in an effect without unsubscribing in cleanup - 2Calling
setStatein a click handler after an async request - 3A large number of components wrapped in
React.memo
Explanation
The handler holds a closure with the component's data, which isn't freed after unmounting; repeated mounts accumulate subscriptions. Similar sources: uncleared timers, unbounded global caches, references to detached DOM nodes. Find them with Memory snapshots in DevTools.