Androidアプリは 限られたメモリ で動作し、メモリ不足の状況ではシステムによってアプリが終了させられる対象となります。メモリ管理、特に メモリリークの回避(よくある深刻なAndroidの問題)を理解することは、安定して高性能なアプリのために重要です。
Androidメモリの基本
→ Apps have a LIMITED heap; the system can KILL background apps to reclaim memory
→ Garbage collection reclaims unreachable objects — but GC pauses can cause jank, and
objects that STAY reachable (leaks) are never collected
→ Low-memory devices are common (Android's range) → memory efficiency matters
メモリリーク — よくある問題
A LEAK = an object that's no longer needed but is still REFERENCED (so GC can't free it).
Classic Android leaks:
✗ Holding an ACTIVITY/Context reference beyond its lifecycle:
- a static field or singleton holding an Activity/Context
- a long-lived listener/callback capturing an Activity
- an inner class / non-cancelled coroutine / handler holding the Activity
→ the Activity can't be GC'd after it's destroyed → its whole view tree leaks (big!)
