Finding, fixing & Avoiding Memory Leaks in Android

in android •  3 years ago  (edited)

memory-leaks-in-android-and-solving-that.png

Memory leaks are common issues in Android apps that result in apps glitches, freezes, crashes during their usage.

Most Android native apps are written on Java or Kotlin. That means that we have a Virtual Machine with a Garbage Collector (GC).

A memory leak happens when memory is allocated but never freed. This means the GC is not able to take out the trash once we are done with the takeout.

First of all, we need to find and detect memory leaks in the application. Let’s look over some of the ways and tools you can use to do that:

  • Android Studio Memory Monitor
  • Infer
  • ANR statistics on Google Play Console
  • Crashes with OutOfMemmoryException
  • LeakCanary.

How to fix Memory Leaks

  • Use properly Context-related classes
  • Use official guidelines and look into Dependency Injection or app\data\domain modules
  • Use unregistered listeners carefully
  • Take care of Inner classes and anonymous classes
  • Fix possible Singletons issues
  • Manage Bitmaps easily throw OutOfMemoryException.

Read in detail on how to detect and fix memory leaks in Android in the full post.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Nice post and we should try apps that are found in the playstore, there are many fun and useful apps there and you can try to download them, there are apps to clean the android phone and you can just try to choose from them.