Bitmap在API Level 1中就已經有了, 只不過隨着SDK更新, Google對它的一些內外部接口/實現進行了一些優化或者調整, 主要是內存資源的管理方面. java
- 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. As of Android 3.0 (API level 11), the pixel data is stored on the Dalvik heap along with the associated bitmap.
上述都只是針對單個Bitmap的內存管理, 可是在開發中, 不免會須要管理大量的Bitmap, 那應該怎麼辦? 緩存
在API Level 12中, 能夠經過LruCache來緩存大量的內存Bitmap. 除此以外, 在Android源碼中, 能夠找到, 一個名爲DiskLruCache的類, 它能夠文件形式緩存Bitmap. app
Google Taining 優化