Developing an app which is memory and battery friendly is very rare. Memory is very limited for an app in android. One of the core reasons which makes memory very precious is due to different device specifications, various ways of writing a code. Memory leaks and usage are very visible to the users like scrolling, switching between apps, crashes etc.,
Let’s get started!
Here are some quick tips to optimize Memory:
User memory efficient data structures such as SparseArray (https://developer.android.com/reference/android/util/SparseArray.html)
Request, Estimate and Trim memory if largeheap=true is enabled
Avoid allocation unnecessary objects
Handle Bitmaps (Factor for different screen size and resolution)
Release object references for GC (Garbage collection)
Caching images (Libraries like Glide can help caching pretty well)
Use latest or performance friendly libraries & SDKs
ProGuard (Performs several actions to remove unused methods and leftover code)
Testing for Memory leaks, OOMs, and exceptions.
There are ways in which the memory usage can be exposed. Doing the right tests under various conditions could expose memory risks of your app.
– Testing on Android versions starting from 5.0 to 8.0.1
– App with and without SDKs or libraries that aren’t dependent on your app
– Enabling orientation for Debug versions to identify memory leaks
– Versions with low – mid – high resolutions resources/images
– Different networks speeds
Focusing on optimizing memory and make the app efficient to avoid battery drain and lag could improve user ratings and experience significantly.