fresco icon indicating copy to clipboard operation
fresco copied to clipboard

Post-processed images with roundedCornerRadius xml attribute will lead to OOM in Android 5.0+

Open kevinzetterstrom opened this issue 10 years ago • 4 comments

I am post-processing images in order to apply a blur effect. I would like these images to have a rounded corner radius as well. On Android 5.0 and up this seems to be an issue. On 4.x devices, this is a non-issue.

Here is my xml:

<com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/list_item_simpledraweeview"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        fresco:overlayImage="@drawable/overlay"
        fresco:roundedCornerRadius="3dp"/>

I have 16 images in a RecyclerView. The following code is without post-processing and works as expected. In Android Studio's memory monitor, when scrolling through the images and back, the memory usage is constant.

ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
            .setResizeOptions(new ResizeOptions(width, height))
            .build();
PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder()
            .setOldController(simpleDraweeView.getController())
            .setImageRequest(request)
            .build();
simpleDraweeView.setController(controller);

The moment I change the ImageRequest to

ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
            .setPostprocessor(new BlurPostProcessor())
            .setResizeOptions(new ResizeOptions(width, height))
            .build();

...things start to get wonky.

The first thing I notice is in the memory management tool of Android Studio - the memory is on a steady incline when scrolling through the images now. Pressing the Garbage Collection button does nothing to free up memory. If I remove the roundedCornerRadius attribute from the xml, the memory looks fine to me - Android Studio shows a constant horizontal line of memory usage.

The second thing I notice is that the blurred images take a second to come in to view when scrolling back through the images in the RecyclerView. I can see the overlay drawable before the blurred image for a split second. I have read the documentation on caching post-processed images, and believe I am abiding by the rules to this, using the following in my BlurPostProcessor (extends BasePostprocessor) :

private final SimpleCacheKey mCacheKey = new SimpleCacheKey("Blur");
@Override
public CacheKey getPostprocessorCacheKey() {
    return mCacheKey;
}

I have a ImageCacheStatsTracker and notice onBitmapCacheMiss gets called - shouldn't the images be in the bitmap cache when using the above? When these are not post-processed, this is the case.

I am more concerned about the first issue, as increasing the memory usage will eventually lead to an OOM. Please advise on what I can do to correct both of these!

kevinzetterstrom avatar Dec 17 '15 17:12 kevinzetterstrom

I met the same problem

wangmeng1989 avatar Dec 18 '15 04:12 wangmeng1989

hey, have you fixed this problem? : (

mavisli avatar May 23 '16 08:05 mavisli

Can you provide logs or stacktraces? It is quite possible that if you are getting OOMs, they happen for completely unrelated reason. I don't think rounded corners has anything to do with this. Post-processing requires additional bitmap to be created and that's just the way it is. We added caching of post-processed images some time ago so that might help.

plamenko avatar May 23 '16 13:05 plamenko

Closing as no further information was provided

erikandre avatar Jul 11 '17 16:07 erikandre