1

我有一个大位图,用Bitmap.createBitmap(). 写作有没有意义

bitmap = null;

就在之前

bitmap = Bitmap.createBitmap();

让GC在构建新位图时使用旧位图占用的内存。

API 级别为 11。

谢谢你。

4

2 回答 2

0

http://www.youtube.com/watch?v=_CruQY55HOk

Look at the video around 11:23. The guy talks about bitmap memory management

Its left to the garbage collector to free memory. Instead of bitmap = null use bitmap.recycle() on andorid 2.3.3 and lower. Use BitmapFactory.Options.inBitmap on 3.0 and higher

Android - Bitmap and memory management?

http://developer.android.com/training/displaying-bitmaps/manage-memory.html

On android 2.3.3 and lower

On Android 2.3.3 (API level 10) and lower, using recycle() is recommended. If you're displaying large amounts of bitmap data in your app, you're likely to run into OutOfMemoryError errors. The recycle() method allows an app to reclaim memory as soon as possible.

On android 3.0 and higher

The bitmap pixel data is stored on the heap

Android 3.0 (API Level 11) introduces the BitmapFactory.Options.inBitmap field. If this option is set, decode methods that take the Options object will attempt to reuse an existing bitmap when loading content. This means that the bitmap's memory is reused, resulting in improved performance, and removing both memory allocation and de-allocation.

Also check this might help

http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

于 2013-09-09T09:21:52.987 回答
0

bitamp = null;不会保证 GC 会释放位图对象占用的内存。因为 Bitmap 是一个最终类,所以最终对象的优先级对于 GC 来说非常低。使用bitmap.recycle()方法确保垃圾收集(GC)。

于 2013-09-09T09:19:14.523 回答