byte[] buffer memory allocations keeps growing?
This is similar to https://github.com/bumptech/glide/issues/785 , in which GifDecode byte[] buffer memory allocations keeps growing, but not sure, if I have to add it as comment in the same issue, since it is in author-review-pending state. Hence raising as a new issue.
I'm using glide 3.7.0, while scrolling in a list of 30-40 gif images ( I can see lot of byte arrays as mentioned in https://github.com/bumptech/glide/issues/785, accumulated over time) I am using glide like
Glide.with(myapplicationcontext)
.load(uri)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.crossFade()
.fitCenter()
.placeholder(R.drawable.placeholder)
.into(imageView);
from my CursorAdapter's bindView().
And my ImageView looks like
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:maxHeight="@dimen/max_width"
android:maxWidth="@dimen/max_width"/>
The scrolling is laggy and out of memory error is thrown, after sometime.

I can see
java.lang.OutOfMemoryError: Failed to allocate a 863052 byte allocation with 244432 free bytes and 238KB until OOM
at com.bumptech.glide.gifdecoder.GifDecoder.setData(GifDecoder.java:380)
at com.bumptech.glide.load.resource.gif.GifDrawable.<init>(GifDrawable.java:92)
at com.bumptech.glide.load.resource.gif.GifDrawable$GifState.newDrawable(GifDrawable.java:368)
at com.bumptech.glide.load.resource.drawable.DrawableResource.get(DrawableResource.java:32)
at com.bumptech.glide.load.resource.drawable.DrawableResource.get(DrawableResource.java:16)
at com.bumptech.glide.load.engine.EngineResource.get(EngineResource.java:44)
at com.bumptech.glide.request.GenericRequest.onResourceReady(GenericRequest.java:487)
at com.bumptech.glide.load.engine.EngineJob.handleResultOnMainThread(EngineJob.java:158)
at com.bumptech.glide.load.engine.EngineJob.access$100(EngineJob.java:22)
at com.bumptech.glide.load.engine.EngineJob$MainThreadCallback.handleMessage(EngineJob.java:202)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:228)
at android.app.ActivityThread.main(ActivityThread.java:5514)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Failed to allocate a 2067852 byte allocation with 443680 free bytes and 433KB until OOM
at 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 2067852 byte allocation with 443680 free bytes and 433KB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:831)
at android.graphics.Bitmap.createBitmap(Bitmap.java:808)
at android.graphics.Bitmap.createBitmap(Bitmap.java:775)
at com.bumptech.glide.load.resource.bitmap.TransformationUtils.fitCenter(TransformationUtils.java:112)
at com.bumptech.glide.load.resource.bitmap.FitCenter.transform(FitCenter.java:24)
at com.bumptech.glide.load.resource.bitmap.BitmapTransformation.transform(BitmapTransformation.java:54)
at com.bumptech.glide.load.engine.DecodeJob.transform(DecodeJob.java:236)
at com.bumptech.glide.load.engine.DecodeJob.transformEncodeAndTranscode(DecodeJob.java:139)
at com.bumptech.glide.load.engine.DecodeJob.decodeFromSource(DecodeJob.java:129)
at com.bumptech.glide.load.engine.EngineRunnable.decodeFromSource(EngineRunnable.java:122)
at com.bumptech.glide.load.engine.EngineRunnable.decode(EngineRunnable.java:101)
at com.bumptech.glide.load.engine.EngineRunnable.run(EngineRunnable.java:58)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
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)
getting printed a lot of times, when I run into OOM
I tried clearing memory cache and disk cache on onTrimMemory() manually (although I found it mentioned in some other issues it may not be needed). Also I tried
case SCROLL_STATE_IDLE:
Glide.with(view.getContext()).resumeRequests();
break;
case SCROLL_STATE_TOUCH_SCROLL:
case SCROLL_STATE_FLING:
Glide.with(view.getContext()).pauseRequests();
break;
on scroll state changed. But still its running to OOM
The other issue is not in any state, each "added" entry has a corresponding "removed" as well. The current state is always what you see in the right column. But it doesn't matter because it's better to have each issue separate as it may turn out it's not the same and investigation can take a lot of space. Thank you for the detailed report. I'll try to reproduce this over the weekend, if you can create a small repro app it would be even better.
I think your selected byte arrays are the active ones, but may be not. When looking for leaks always do a path to GC root query to see what is keeping it in memory.
I just had a look at heap dump with mat.. the leak suspects were
21 instances of "com.bumptech.glide.load.engine.EngineJob", loaded by "dalvik.system.PathClassLoader @ 0x12d13680" occupy 49,375,560 (43.15%) bytes.
Biggest instances:
com.bumptech.glide.load.engine.EngineJob @ 0x131525c0 - 3,469,640 (3.03%) bytes.
com.bumptech.glide.load.engine.EngineJob @ 0x131d3200 - 3,469,640 (3.03%) bytes.
com.bumptech.glide.load.engine.EngineJob @ 0x1329f840 - 3,469,640 (3.03%) bytes.
com.bumptech.glide.load.engine.EngineJob @ 0x13107680 - 3,339,680 (2.92%) bytes.
com.bumptech.glide.load.engine.EngineJob @ 0x13273740 - 2,798,808 (2.45%) bytes.
com.bumptech.glide.load.engine.EngineJob @ 0x13171bc0 - 2,776,808 (2.43%) bytes.
com.bumptech.glide.load.engine.EngineJob @ 0x130a4f80 - 2,538,944 (2.22%) bytes.
com.bumptech.glide.load.engine.EngineJob @ 0x1326e880 - 2,538,944 (2.22%) bytes.
com.bumptech.glide.load.engine.EngineJob @ 0x132a4200 - 2,538,944 (2.22%) bytes.
com.bumptech.glide.load.engine.EngineJob @ 0x131d5400 - 2,073,976 (1.81%) bytes.
com.bumptech.glide.load.engine.EngineJob @ 0x131d5640 - 2,073,976 (1.81%) bytes.
com.bumptech.glide.load.engine.EngineJob @ 0x131d5880 - 2,073,976 (1.81%) bytes.
com.bumptech.glide.load.engine.EngineJob @ 0x131d5b00 - 2,073,976 (1.81%) bytes.
com.bumptech.glide.load.engine.EngineJob @ 0x131dc200 - 2,073,976 (1.81%) bytes.
com.bumptech.glide.load.engine.EngineJob @ 0x1328b680 - 2,073,976 (1.81%) bytes.
com.bumptech.glide.load.engine.EngineJob @ 0x1328b980 - 2,073,976 (1.81%) bytes.
com.bumptech.glide.load.engine.EngineJob @ 0x131dc540 - 2,068,216 (1.81%) bytes.
com.bumptech.glide.load.engine.EngineJob @ 0x131dcbc0 - 2,068,216 (1.81%) bytes.
com.bumptech.glide.load.engine.EngineJob @ 0x131dc880 - 2,045,176 (1.79%) bytes.
com.bumptech.glide.load.engine.EngineJob @ 0x13245540 - 1,270,784 (1.11%) bytes.
These instances are referenced from one instance of "java.util.HashMap$HashMapEntry[]", loaded by "<system class loader>"
Keywords
dalvik.system.PathClassLoader @ 0x12d13680
java.util.HashMap$HashMapEntry[]
com.bumptech.glide.load.engine.EngineJob
Details »
Problem Suspect 2
22 instances of "com.bumptech.glide.request.GenericRequest", loaded by "dalvik.system.PathClassLoader @ 0x12d13680" occupy 20,707,432 (18.10%) bytes.
Biggest instances:
com.bumptech.glide.request.GenericRequest @ 0x12e2e680 - 2,074,320 (1.81%) bytes.
com.bumptech.glide.request.GenericRequest @ 0x12e2e880 - 2,074,320 (1.81%) bytes.
com.bumptech.glide.request.GenericRequest @ 0x12e2eb00 - 2,074,320 (1.81%) bytes.
com.bumptech.glide.request.GenericRequest @ 0x12e30200 - 2,074,320 (1.81%) bytes.
com.bumptech.glide.request.GenericRequest @ 0x12e30680 - 2,074,320 (1.81%) bytes.
com.bumptech.glide.request.GenericRequest @ 0x12e41d00 - 2,074,320 (1.81%) bytes.
com.bumptech.glide.request.GenericRequest @ 0x12e44080 - 2,074,320 (1.81%) bytes.
com.bumptech.glide.request.GenericRequest @ 0x12e30d80 - 2,068,560 (1.81%) bytes.
com.bumptech.glide.request.GenericRequest @ 0x12e33880 - 2,068,560 (1.81%) bytes.
com.bumptech.glide.request.GenericRequest @ 0x12e33280 - 2,045,520 (1.79%) bytes.
Keywords
dalvik.system.PathClassLoader @ 0x12d13680
com.bumptech.glide.request.GenericRequest
I'll upload screenshots..

Any updates on this issue? I tried MAT & it show the same leak suspects as well.
This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.
how can i see this call stuck in android studio? seems like many libraries are poorly written.