赞
踩
其实这个官方有很明确的说明,但是之前看过别人写的一些文章,是错的,怎么说的都有,导致自己记忆起来也是乱七八糟。 所以现在排净脑子中之前的垃圾信息,从新记忆 官方Managing Bitmap Memory一文中指出:
On Android Android 2.2 (API level 8) and lower, when garbage collection occurs, your app's threads get stopped. This causes a lag that can degrade performance. Android 2.3 adds concurrent garbage collection, which means that the memory is reclaimed soon after a bitmap is no longer referenced.
On Android 2.3.3 (API level 10) and lower, the backing pixel data for a bitmap is stored in native memory. It is separate from the bitmap itself, which is stored in the Dalvik heap. 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. From Android 3.0 (API level 11) through Android 7.1 (API level 25), the pixel data is stored on the Dalvik heap along with the associated bitmap. In Android 8.0 (API level 26), and higher, the bitmap pixel data is stored in the native heap.
是不是很明显,白纸黑字。
1 android2.2(API level 8)和更早的版本,垃圾回收时,会阻塞UI线程,造成卡顿。
而2.3(API level 9)开始增加了并行的垃圾回收机制,可以让应用得到更好的体验。
2 android2.3.3(API level 10)和更早的版本,bitmap对象和对象里对应的像素数据是分开存储的,bitmap存在虚拟机的堆里,而像素数据存储在native内存里。
从android3.0(API level 11)到android7.1(API level 25),bitmap对象及其像素数据都存储在虚拟机的堆里。
从android8.0(API level 26)开始,bitmap对象存储在虚拟机的堆里,而对应的像素数据存储在native堆里。
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。