Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
mobile ruleP0stack specificStack: android
androidmemorycontext-leak
Don't hold Activity/Context references in long-lived objects
Static or long-lived references to an Activity/Context leak the whole view tree; use applicationContext or weak refs.
PR: mobile-canon-2026-06Created: Jul 5, 2026
Bad example
Old codekotlin
| 1 | object Cache { lateinit var ctx: Activity } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codekotlin
| 1 | class Cache(context: Context) { private val app = context.applicationContext } |
Explanation (EN)
Objašnjenje (HR)