ANR & Memory Management
PERFORMANCE › Runtime
Keeping the main thread free and references scoped to avoid ANRs, leaks, and OOM.
ANR and memory questions probe whether you understand what blocks the main thread and what keeps objects alive longer than they should be. Interviewers expect exact ANR thresholds, the standard prevention patterns (coroutines, WorkManager, goAsync), and the classic leak sources plus how you would detect and fix them. Expect to reason about lifecycle, references, and bitmaps rather than just recite definitions.
What this covers
- Exact ANR thresholds: 5s input dispatch, 10s foreground BroadcastReceiver, 20s foreground Service
- Why the main thread blocks: slow I/O, heavy computation, lock contention, deadlock, synchronous binder calls
- Modern prevention: coroutines on background dispatchers, WorkManager, and goAsync() in receivers (AsyncTask is deprecated)
- Classic leak sources: static Activity/Context refs, non-static inner classes/Handlers, unregistered listeners and receivers
- References and lifecycle: WeakReference vs SoftReference, applicationContext, ViewModel and viewModelScope
- OOM and tooling: per-app heap cap, bitmap sizing (ARGB_8888), onTrimMemory, LeakCanary, Memory Profiler, StrictMode
Study this topic
- ANR & Memory Management explained: the guided lesson
- 14 practice quiz questions
- 9 revision flashcards
- ANR & Memory Management interview questions and answers