fresco icon indicating copy to clipboard operation
fresco copied to clipboard

Dalvik heap memory alway increase

Open KrystalJake1989 opened this issue 11 years ago • 4 comments

I config my bitmap cache like follow,but I find the dalvik memory increase more and more, when I scroll the listview and jump between activities

public class MemoryCacheSupplier implements Supplier {

private static final int NORMAL_SIZE = 8 * ByteConstants.MB; //byte
private static final int LARGE_SIZE = 16 * ByteConstants.MB; //byte
private static final int SUPER_SIZE = 32 * ByteConstants.MB; //byte
private static final int EXTRA_SUPER_SIZE = 64 * ByteConstants.MB; //byte

@Override
public MemoryCacheParams get() {
    ActivityManager am = (ActivityManager) AppUtil.getAppContext().getSystemService(Context.ACTIVITY_SERVICE);
    int totalMemorySize = am.getMemoryClass() * ByteConstants.MB;

    int memorySize = 0;

    if(totalMemorySize <= NORMAL_SIZE){
        memorySize = totalMemorySize >> 5;
    }else if(NORMAL_SIZE < totalMemorySize && totalMemorySize <= LARGE_SIZE){
        memorySize = totalMemorySize >> 5;
    }else if(totalMemorySize < SUPER_SIZE && totalMemorySize <= EXTRA_SUPER_SIZE){
        memorySize = Math.round(totalMemorySize * 0.15f);
    }else if(totalMemorySize > EXTRA_SUPER_SIZE){
        memorySize = totalMemorySize >> 5;
    }

    if(memorySize <= 0){
        memorySize = ByteConstants.MB;
    }


    MemoryCacheParams params = new MemoryCacheParams(
            memorySize,Integer.MAX_VALUE,memorySize,Integer.MAX_VALUE,Integer.MAX_VALUE);

    return params;
}

}

KrystalJake1989 avatar May 20 '15 08:05 KrystalJake1989

Interesting. Cache is one of the places that can keep big bitmaps around. Another place is a view. Do you use Drawee to display images ? Is it SimpleDraweeView or something else ?

michalgr avatar May 20 '15 09:05 michalgr

Yes,I just use SimpleDraweeView in xml layout and load image through the recommended method

@Override protected void bindFeedPic(SimpleDraweeView view, String uri, int width, int height) { ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(uri)) .setResizeOptions( new ResizeOptions(width, height)) .setAutoRotateEnabled(false) .build(); DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setImageRequest(imageRequest) .setOldController(view.getController()) .build(); view.setController(draweeController); }

KrystalJake1989 avatar May 20 '15 09:05 KrystalJake1989

I find if I use a normal png image as placeholder,then the dalvik heap will be increased while I jump between activities.But If I don't set placeholder or I use drawable xml,then the dalvik heap as expected increase and go down a bit.Dose fresco support to use png image as placeholder?

KrystalJake1989 avatar May 21 '15 11:05 KrystalJake1989

Placeholders are loaded by using the Android's built-in facility resources.getDrawable. Fresco doesn't do anything special there.

plamenko avatar Jul 08 '15 14:07 plamenko