I'm making modifications to the Android 4.0 launcher and I have been running into many OutOfMemoryErrors. Since the 4.0.3 update it got much worse (or started, it seems before it was fine, but I never got to test properly) and I have tried many many things to fix it. The error is also in the stock launcher without my modifications.

I looked at the heap hprof in the Eclipse Memory Analyzer and noticed that the system Resources class was taking 50% of the memory. Almost all of it was Bitmaps including some bitmaps that were 1mb 512x512px. Since my phone is 400x800, I don't see why it would have a resource at that resolution. Then there were there more than 800 other bitmaps as well but these were more reasonable sizes.

The app doesn't contain 800 resources, so is it possible that these are from other packages? I know the app does load icons and widget previews from other apps, but that still isn't up to 800 and even if it is part of them, why is it still being kept in memory?

2 Answers
2

There is a 'feature' in the Bitmap class of Android that keeps Bitmaps out of your VM heap size, which in turn means that you have even less space for Bitmaps.

The only way to solve OutOfMemory exceptions that are related to Bitmaps, you'll have to free resources using Bitmap.Recycle(); after you have finished using this Bitmap. And use Runtime.gc() to flush the Garbage Collector.

My personal opinion is that this sucks and that Bitmaps should also be included in your app's VM heap size, but that's just not the case in Android.