why native memory does not release when use the bitmap.recycle()
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"); }
Is this related to the Fresco library?
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.
How do you measure native memory and which Android version do you use ?
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
I didn't use the CloseableReference, just recycled bitmap menually