开发者

Android Bitmap.createBitmap() fills heap

I need big Bitmap (6000x2000), so I create one:

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

And then at the end of the method I recycle bm and set it to null. But again, my heap grows every time my method is called. Every time until it throws OutOfMemoryE开发者_JAVA百科rror.


The problem is that it can take a couple of GC cycles for a Bitmap to be properly released on Android before Android 3.x. Even if you call recycle() I believe the bitmap counts against your heap usage until at least the next GC. This is one of the very few situations where I would advise you to force a GC by calling System.gc(). You could also try use several smaller bitmaps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜