Home » Android » out of memory – OutOfMemory error on Android 6.0.1 devices after the second launch

out of memory – OutOfMemory error on Android 6.0.1 devices after the second launch

Posted by: admin May 14, 2020 Leave a comment


My project was working until I updated my S6 Edge to Android 6.0.1.

The app crashes with an OutOfMemory error after the second launch.

The application contains 2000+ images in the directory and I am using a timer to increment a counter and display them on an imageView. When onFinish()/onPause()/onDestroy() is called I am destroying/cancelling all the objects such as the timers, counter and imageView by setting them to null.

This is how I am fetching/printing the image to the imageView

int resID = getResources().getIdentifier("animation"+i , "drawable", getPackageName());
    Drawable animationFrame = ContextCompat.getDrawable(this, resID);

It runs on initial launch (even if I install the app using a generated APK). When I remove the app from the minimised applications, the application crashes after 2-3 seconds. I have checked the memory allocated and it is normal (up to 12MB) on the first run whereas on the second the memory allocated is 255MB.

onDestroy() method
This includes ALL my variables initialised. My variables are initialised as private or with no access variable.

protected void onDestroy() {
    animationView = null;
    justAnimation = null;
    buttonSign = null;
    i = 0;
    media  = null;
    deathRateEU = 0;
    deathRateUK = 0;
    labelNumber = null;
    labelNumberUK = null;
    buttonSign = null;
    loadingEU = null;
    loadingUK = null;


Media is a MediaPlayer initialised as public and it plays a sound when counter(i) reaches a point

I installed this on another device that runs Android 5.1.3 (not sure but it is 5.1 something).

Is there is a known bug for OutOfMemory issues when application get minimised on Android 6.0.1?

I am 100% sure that I did not make any changes before/after my phone updated to version 6.0.1

Memory Monitor on 1st Launch
enter image description here

Second Launch
enter image description here


  1. If the application is already installed on the device and I try to compile it using Android Studio, the crash occurs
  2. I have to uninstall/re-compile to manage to get the app working in the first go
  3. I get the same error when I try to run my project on a Genymotion Android 6.0 device, but not on an Android 5.1 genymotion virtual device
How to&Answers:

I would recommend you to use Glide library to efficiently load large images.
You can also check this article about how to efficiently load Bitmaps.