Reputation: 487
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 OutOfMemoryError.
Upvotes: 4
Views: 1672
Reputation: 98501
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.
Upvotes: 3