-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);
6
  • Are you using emulator for testing? Commented Dec 19, 2016 at 9:31
  • We can't really help you without your code Commented Dec 19, 2016 at 9:33
  • I have used real device for testing. Commented Dec 19, 2016 at 9:40
  • can you show us code stackoverflow.com/a/31062339/4741746 check out this Commented Dec 19, 2016 at 9:42
  • reduce image size . add .thumbnail(0.4f) .Glide will display the original image reduced to 40% of the size. Commented Dec 19, 2016 at 9:45

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

2 Comments

I have also used android:largeHeap="true".
I have Used glide so BitmapFactory option is not here,
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.