bitmap size exceeds Vm budget error android

The question:

When I change to landscape mode, few objects are created with bitmap of full screen.

When I scroll the other object is called and its bitmap is displayed, when I doing this repeatedly , bitmap size exceeds vm budget error, I have done all the things like recycle(), set null and then called GC(), still I have same error. creating bitmap….

    bitmap = Bitmap.createBitmap(ChartProperties.getChartWidth(), 

                    new SoftReference(bitmap));

    if(imageCache != null){

        for (int i = 0; i < imageCache.size(); i++) {

            if (imageCache.get(String.valueOf(i)) != null) {
                imageCache.put(String.valueOf(i), null);                    

        imageCache = null;

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

I also had the same problem OOME because of bitmaps.

When orientation changes from PORTRAIT to LANDSCAPE and vice-versa, the previous UI is completely discarded, and a new UI is loaded and displayed, In this case if you are using many bitmaps in your app, you need to release them at proper places.

To check the orientation of your device, please see this: Check orientation on Android phone

In your case, you need to clear bitmaps during orientation change.

On above link you can found, how to get the current orientation. So on each orientation change, call your above code that cleans up the bitmaps.

Now, when we check the logcat, there is always a log comes up saying GC_, but I could not understand that, so
I found an amazing doc on memory leak issue:

The above link is very useful for your problem.

Now, the OOME occurs when there is memory leak in your app., so to check that, please install the MAT for eclipse. You can find it at:

Its a bit complicated software but as you go through it, you will understand, its pretty useful software.

Even if this doesn’t solves your problem, use the WeakReference for bitmaps.

Please refer this link: How to use WeakReference in Java and Android development?

If I get know some more info, I will update this post.

Please update your post, if you get solution to your problem.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment