Android Exceptions OutOfMemoryError

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

This is a runtime error that happens when you request a large amount of memory on the heap. This is common when loading a Bitmap into an ImageView.

You have some options:

  1. Use a large application heap

Add the "largeHeap" option to the application tag in your AndroidManifest.xml. This will make more memory available to your app but will likely not fix the root issue.

<application largeHeap="true" ... >
  1. Recycle your bitmaps

After loading a bitmap, be sure to recycle it and free up memory:

    if (bitmap != null && !bitmap.isRecycled())
       bitmap.recycle();
  1. Load sampled bitmaps into memory

Avoid loading the entire bitmap into memory at once by sampling a reduced size, using BitmapOptions and inSampleSize.

See Android documentation for example



Got any Android Question?