React Native & Expo (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
Memory Leak Detection in Mobile Apps: Native retain cycles, orphaned listeners, and profiling tools.
senior LevelPerformanceMemory Management
In Simple Words: Detecting why an app crashes after 30 minutes of usage:
- JavaScript Retain Cycles: Forgotten global event listeners (
AppState.addEventListener,setInterval) that are never cleaned up on component unmount. - Native Retain Cycles (Swift/Kotlin): Strong reference cycles between closures and ViewControllers (resolve with
[weak self]). - Profiling: Use Xcode Instruments (Allocations & Leaks) on iOS and Android Studio Memory Profiler to inspect native heap memory graphs and identify un-garbage-collected objects.