[英]How is a bitmap's memory managed on Android?
I am following this article on Android developer, which quotes : 我正在关注Android开发者的这篇文章 , 该文章引述:
On Android 2.3.3 (API level 10) and lower, the backing pixel data for a bitmap is stored in native memory. 在Android 2.3.3(API级别10)及更低版本中,位图的支持像素数据存储在本机内存中。 It is separate from the bitmap itself, which is stored in the Dalvik heap. 它与位图本身是分开的,位图本身存储在Dalvik堆中。 The pixel data in native memory is not released in a predictable manner, potentially causing an application to briefly exceed its memory limits and crash. 本机内存中的像素数据不会以可预测的方式释放,可能导致应用程序短暂超出其内存限制并崩溃。 As of Android 3.0 (API level 11), the pixel data is stored on the Dalvik heap along with the associated bitmap. 从Android 3.0(API级别11)开始,像素数据与关联的位图一起存储在Dalvik堆上。
There is another article which confused me further : 还有一篇文章让我更加困惑:
A Bitmap is a thin wrapper around a native heap memory area that stores pixel data. Bitmap是存储像素数据的本机堆内存区域的薄包装器。
I have multiple doubts : 我有很多疑惑:
When having an OutOfMemoryError, try the code below. 遇到OutOfMemoryError时,请尝试以下代码。
try {
bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), m, true);
return bitmap;
} catch (OutOfMemoryError e) {
bitmap.recycle();
bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), m, true);
return bitmap;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.