Finding, fixing & Avoiding Memory Leaks in Android

in #android3 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.

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.029
BTC 61830.18
ETH 2457.48
USDT 1.00
SBD 2.54