Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fe9714c4 authored by Uday Kiran jandhyala's avatar Uday Kiran jandhyala Committed by Linux Build Service Account
Browse files

Use WeakReferenes to reduce Bitmap memory footprint

Use HashMap<Integer, WeakReference<Drawable>> instead of just
    HashMap<Integer, Drawable>

Without this, references are still being held for Bitmap drawables,
thereby after few Photo edits, OutOfMemoryException is raised and
Gallery crashes

Change-Id: If91f950986bd816d5571a0d51a7cb9522226e270
parent 07a1c98a
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

import java.util.HashMap;
import java.lang.ref.WeakReference;

public class ImageFilterBorder extends ImageFilter {
    private static final float NINEPATCH_ICON_SCALING = 10;
@@ -32,7 +33,7 @@ public class ImageFilterBorder extends ImageFilter {
    private FilterImageBorderRepresentation mParameters = null;
    private Resources mResources = null;

    private HashMap<Integer, Drawable> mDrawables = new HashMap<Integer, Drawable>();
    private HashMap<Integer, WeakReference<Drawable>> mDrawables = new HashMap<Integer, WeakReference<Drawable>>();

    public ImageFilterBorder() {
        mName = "Border";
@@ -81,10 +82,10 @@ public class ImageFilterBorder extends ImageFilter {
    }

    public Drawable getDrawable(int rsc) {
        Drawable drawable = mDrawables.get(rsc);
        Drawable drawable = (mDrawables.get(rsc) != null) ? mDrawables.get(rsc).get() : null;
        if (drawable == null && mResources != null && rsc != 0) {
            drawable = new BitmapDrawable(mResources, BitmapFactory.decodeResource(mResources, rsc));
            mDrawables.put(rsc, drawable);
            mDrawables.put(rsc, new WeakReference<Drawable>(drawable));
        }
        return drawable;
    }