Java – Android bitmap. Createbitmap() fills the heap

I need a big bitmap (6000) × 2000), so I created a:

Bitmap.Config conf = Bitmap.Config.ARGB_4444;
Bitmap bm = Bitmap.createBitmap(6000, 2000, conf);

Then at the end of the method, I reclaim BM and set it to null. However, every time I call my method, my heap will grow. Outofmemoryerror will be thrown every time

resolvent:

The problem is that before Android 3. X, it may take several GC cycles to correctly publish bitmap on Android. Even if you call recycle (), I believe the bitmap will be accounted for in your heap usage until at least the next GC. This is one of the very few cases where I suggest you enforce GC by calling system. GC (). You can also try to use several smaller bitmaps

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>