-4

How to solve OutOfMemoryError in Glide Image Loading .

Caused by: java.lang.OutOfMemoryError: Failed to allocate a 5137932 byte allocation with 923120 free bytes and 901KB until OOMSent on:2:54 threw uncaught throwablejava.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Failed to allocate a 5137932 byte allocation with 923120 free bytes and 901KB until OOMat java.util.concurrent.FutureTask.report(FutureTask.java:94)at java.util.concurrent.FutureTask.get(FutureTask.java:164)at

com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor.afterExecute(FifoPriorityThreadPoolExecutor.java:96)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1121)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)at java.lang.Thread.run(Thread.java:818)at com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor$DefaultThreadFactory$1.run(FifoPriorityThreadPoolExecutor.java:118)Caused by: java.lang.OutOfMemoryError: Failed to allocate a 5137932 byte allocation with 923120 free bytes and 901KB until OOMat dalvik.system.VMRuntime.newNonMovableArray(Native Method)at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:882)at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:858)at com.bumptech.glide.load.resource.bitmap.Downsampler.decodeStream(Downsampler.java:329)at com.bumptech.glide.load.resource.bitmap.Downsampler.downsampleWithSize(Downsampler.java:220)at com.bumptech.glide.load.resource.bitmap.Downsampler.decode(Downsampler.java:153)at com.bumptech.glide.load.resource.bitmap.StreamBitmapDecoder.decode(StreamBitmapDecoder.java:50)at com.bumptech.glide.load.resource.bitmap.StreamBitmapDecoder.decode(StreamBitmapDecoder.java:19)at com.bumptech.glide.load.resource.bitmap.ImageVideoBitmapDecoder.decode(ImageVideoBitmapDecoder.java:39)at com.bumptech.glide.load.resource.bitmap.ImageVideoBitmapDecoder.decode(ImageVideoBitmapDecoder.java:20)at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decodeBitmapWrapper(GifBitmapWrapperResourceDe

Glide Image Loder Code for loading Images

Glide.with(activity)
            .load(items.get(position).getCharacterImageId(activity.getResources()))                   .placeholder(items.get(position).getColor(activity.getResources()))
                .dontAnimate()
                .thumbnail(0.7f)
                .into(img_letter);
sanjeev kumar
  • 541
  • 4
  • 20

2 Answers2

1
 android:largeHeap="true"

Use this line in your manifest file like :

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

If problem not solved then use this:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
mBitmapInsurance = BitmapFactory.decodeFile(mCurrentPhotoPath,options);
Rishabh Mahatha
  • 1,251
  • 9
  • 19
0

You can use android:largeHeap="true" to request a larger heap size, but this will not work on any pre Honeycomb devices. On pre 2.3 devices, you can use the VMRuntime class, but this will not work on Gingerbread and above.

Aiyaz Parmar
  • 562
  • 6
  • 17