Your crash dashboard is sorted by frequency. That is a sensible default, and it hides one whole class of defect. A memory leak does not produce one crash a thousand times. It produces a thousand different crashes once each.
Why It Hides
The maintainers of the standard Android leak detection tool explain the mechanism: "When memory is low because of memory leak accumulation, an OOM can be thrown from anywhere in the app code, which means that every OOM has a different stacktrace" (LeakCanary). Each lands at the bottom of the list, below the threshold anyone triages.
Many leaks never crash at all. The operating system closes the app first, to protect the phone. To the customer, the app forgot where they were. To your dashboard, nothing happened.
What It Costs Before It Crashes
The same source describes the slow part: "As small memory leaks accumulate, memory usage grows, the Garbage Collector (GC) runs more frequently and consumes more CPU, causing jank, UI freezes and Application Not Responding (ANR) reports, eventually leading to an OutOfMemoryError (OOME) crash." Stutter and freezes come first. The crash is the last symptom, not the first.
One Number With a Source
Our engineering article on this subject used to open with industry statistics. None had a source, and all are removed. The one figure we could trace is narrow, and it is about a single app: "When Square engineers first enabled LeakCanary in the Square Point Of Sale app, they were able to fix several leaks and reduced the OOM crash rate by 94%."
The Popular Fix Does Not Work
There is a standard quick patch for a leak, and our article recommended it. The maintainers are unambiguous: "Memory leaks cannot be fixed by replacing strong references with weak references." The original defect stays and new ones arrive. A team that reports a leak as fixed this way has moved it.
What to Ask Your Team
- Do we run leak detection in every development build? It is one line of configuration.
- How many times a day does the system close our app for memory? The platform will tell you if you ask it.
- How do we group out-of-memory crashes? By stack trace is the wrong answer.
- When a leak is fixed, what changed?
-Rocky
#SoftwareReliability #AppStability #MobileEngineering #EngineeringDreams #StrategiaX
Originally published on ANDROID-ARCHITECT, the Android engineering blog of Strategia-X, with the tooling, the patterns and the code.
