Interview frequency: …
Short answer
Take memory snapshots and monitor the Xcode Memory Gauge and Android Studio Profiler for unreleased native objects and activities, and review useEffect cleanup for timers and subscriptions.
Explanation
Leaks happen when event listeners are not removed, references to large images are retained in global variables, or asynchronous operations update a component after it has unmounted. Accumulated memory can trigger an Out of Memory (OOM) event and force-close the app.
Code example
// Prevent memory leaks during long network requests:
useEffect(() => {
const controller = new AbortController();
fetchUserData({ signal: controller.signal })
.then(data => setUser(data))
.catch(err => { if (err.name !== 'AbortError') console.error(err); });
return () => controller.abort(); // Immediate cancellation when leaving the screen
}, [userId]);Common mistakes
- Failing to clean up setInterval timers and AppState listeners when a component unmounts.