fresco icon indicating copy to clipboard operation
fresco copied to clipboard

why native memory does not release when use the bitmap.recycle()

Open chanderwoo opened this issue 11 years ago • 5 comments

I use the follow method to decode bitmap and then use bitmap.recycle() to release in my cache manage strategy.But the native memory does not release. why?

/**

  • Performs the actual decoding. */ private Bitmap doDecodeBitmap(final byte[] encodedBytes,final int length,Bitmap.Config config) { final Bitmap bitmap = decodeAsPurgeableBitmap(encodedBytes, length, config);

    try { // Real decoding happens here - if the image was corrupted, this will throw an exception Bitmaps.pinBitmap(bitmap); } catch (Exception e) { bitmap.recycle(); throw Throwables.propagate(e); } return bitmap; }

    /**

  • Decode the input into a purgeable bitmap *

  • @param encodedBytes the input encoded image

  • @return a purgeable bitmap */ @SuppressLint("NewApi") private static Bitmap decodeAsPurgeableBitmap( byte[] encodedBytes, int size, Bitmap.Config config) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inDither = true; options.inPreferredConfig = config;

    options.inPurgeable = true; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { options.inMutable = true; } Bitmap bitmap = BitmapFactory.decodeByteArray( encodedBytes, 0, size, options); return Preconditions.checkNotNull(bitmap, "BitmapFactory returned null"); }

chanderwoo avatar Aug 17 '15 13:08 chanderwoo

Is this related to the Fresco library?

plamenko avatar Aug 18 '15 14:08 plamenko

It is not related to the Fresco library.I just use the DalvikBitmapFactory class. There is any diffrence with java head to recycle bitmap? I had also try to unPin and didn't work. Please help...Thank you.

chanderwoo avatar Aug 19 '15 05:08 chanderwoo

How do you measure native memory and which Android version do you use ?

michalgr avatar Aug 19 '15 09:08 michalgr

I have try 4.2.2、 4.3 SNAPSHOT Android version. measure method: 1、adb shell dumpsys meminfo xxx 2、native heap in DDMS tool

chanderwoo avatar Aug 20 '15 09:08 chanderwoo

I didn't use the CloseableReference, just recycled bitmap menually

chanderwoo avatar Aug 20 '15 09:08 chanderwoo