facebook / facebook/fresco

load animated webp with OOM

Open
#2,631 2 comments 0 reactions 0 assignees View on GitHub
stale
Dominant language
Kotlin
Stars
17.2k
Forks
3.7k
PR merge metrics
No merged PRs in 30d

Description

We use GitHub Issues for bugs.

If you have a non-bug question, please ask on Stack Overflow: http://stackoverflow.com/questions/tagged/fresco

--- Please use this template, and delete everything above this line before submitting your issue ---

### Description

I use fresco to load an animated webp with CACHING_STRATEGY_FRESCO_CACHE, then OOM happened

### Reproduction

initialize fresco with
ImagePipelineConfigInterface.getCloseableReferenceLeakTracker = {
func isSet(): Boolean = true
}
, and build an DraweeController with new DrawableFactory with CACHING_STRATEGY_FRESCO_CACHE, like this:

class MultiDrawableFactory() : DrawableFactory {
override fun supportsImageType(closeableImage: CloseableImage): Boolean {
return closeableImage is CloseableAnimatedImage
}

override fun createDrawable(closeableImage: CloseableImage): Drawable? {
val closeable = closeableImage as CloseableAnimatedImage
return AnimatedDrawable2(createAnimationBackend(closeable.imageResult!!))
}

private fun createAnimationBackend(animatedImageResult: AnimatedImageResult): AnimationBackend {
val animatedImage = animatedImageResult.image
val animatedDrawableBackend: AnimatedDrawableBackend = AnimatedDrawableBackendImpl(
AnimatedDrawableUtil(),
animatedImageResult,
Rect(0, 0, animatedImage.width, animatedImage.height),
false
)
val bitmapFrameCache: BitmapFrameCache = FrescoFrameCache(
AnimatedFrameCache(AnimationFrameCacheKey(animatedImageResult.hashCode()), ImagePipelineFactory.getInstance().bitmapCountingMemoryCache),
true
)

//val bitmapFrameCache = Cache()
val bitmapFrameRenderer: BitmapFrameRenderer = AnimatedDrawableBackendFrameRenderer(
bitmapFrameCache,
animatedDrawableBackend
)
val bitmapFramePreparer = DefaultBitmapFramePreparer(
ImagePipelineFactory.getInstance().platformBitmapFactory,
bitmapFrameRenderer,
Bitmap.Config.ARGB_8888,
DefaultSerialExecutorService(Executors.newCachedThreadPool())
)
val bitmapAnimationBackend = BitmapAnimationBackend(
ImagePipelineFactory.getInstance().platformBitmapFactory,
bitmapFrameCache,
AnimatedDrawableBackendAnimationInformation(animatedDrawableBackend),
bitmapFrameRenderer,
FixedNumberBitmapFramePreparationStrategy(3),
bitmapFramePreparer
)
return AnimationBackendDelegateWithInactivityCheck.createForBackend(
bitmapAnimationBackend,
RealtimeSinceBootClock.get(),
UiThreadImmediateExecutorService.getInstance()
)
}
}
look FrescoFrameCache with reuse

val controller: DraweeController = Fresco.newDraweeControllerBuilder()
.setUri("https://p3-webcast.douyinpic.com/img/webcast/audio_bg_6_animated_3.webp~tplv-obj.image")
.setCustomDrawableFactory(MultiDrawableFactory())
.setAutoPlayAnimations(true)
.build()
binding.myImageView.controller = controller

### Solution

what lead to OOM is function clone in class DefaultCloseableReference: mStacktrace != null ? new Throwable(mStacktrace), so many Throwable would be created. use mStacktrace != null ? mStacktrace instead of it

### Additional Information

* Fresco version: all
* Platform version: android

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.