Fresco: placeholder cause memory leak

Created on 13 Jan 2016  路  4Comments  路  Source: facebook/fresco

my code in xml is

        <com.facebook.drawee.view.SimpleDraweeView
            android:layout_width="0dp"
            fresco:placeholderImage="@drawable/thisone_placeholder"
            fresco:actualImageScaleType="fitCenter"
            android:layout_height="wrap_content"
            fresco:viewAspectRatio="0.5625"
            android:layout_weight="1" />

thisone_placeholder_left is a jpg, when i use this, the memory increase fast.
and after i move it, it become normal.

needs-details

Most helpful comment

Small or not, a leak is a leak.

All 4 comments

Fresco does not do anything fancy about placeholder images - whatever you specify, it will be obtained via Resources.getDrawable (https://github.com/facebook/fresco/blob/94ce1dee0733300fe2c029382e0c454169db81b8/drawee/src/main/java/com/facebook/drawee/view/GenericDraweeView.java#L246).

Could you check whether the memory grows because the thisone_placeholder image is that big or because multiples instances of bitmaps are created (one per drawable) ? You can check that in heapdump.

I confirm this.

I had a grid view with several images using a big JPEG as placeholder (for testing), and the app was crashing by memory shortage. I removed the placeholder and did the old way, checking if there's an image, else loading the placeholder as an actual image, and the leak stopped.

Here's Android Studio memory allocation analysis: 2016.02.10_21.04.zip

Placeholders are meant to be small, quickly-loaded images. If you need to use a large image there, you should use a low-res request instead.

Small or not, a leak is a leak.

Was this page helpful?
0 / 5 - 0 ratings