位图的大小超过VM预算错误的android [英] bitmap size exceeds Vm budget error android

查看:122
本文介绍了位图的大小超过VM预算错误的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我改变为横向模式,几个对象都与全屏位图创建。

当我滚动其他对象称为其位图显示,当我做这个反反复复,位图的大小超过 VM 预算错误,我已经做了所有的事情一样循环(),设置为空值,然后叫 GC(),我仍然有同样的错误。创建位图....

 位= Bitmap.createBitmap(ChartProperties.getChartWidth()
                    ChartProperties.getChartHeight(),
    Bitmap.Config.RGB_565);

    imageCache.put(将String.valueOf(LandscapeChartActivity.getActiveFeature()),
                    新SoftReference(位图));

    如果(imageCache!= NULL){

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

            如果(imageCache.get(将String.valueOf(I))!= NULL){
                。imageCache.get(将String.valueOf(I))得到()循环()。
                imageCache.put(将String.valueOf(我),NULL);
            }

        }
        调用Runtime.getRuntime()GC()。
        imageCache.clear();
        imageCache = NULL;
 

解决方案

我也有过,因为位图同样的问题OOME。

当方向改变,从纵向到横向,反之亦然,在previous UI完全丢弃,并且新的用户界面加载并显示,在这种情况下,如果你在你的应用程序中使用许多位图,您需要在适当的地方释放他们。

要检查你的设备的方向,请参阅本:检查取向对Android手机

在你的情况,你需要在方向变化来清除位图。

在你可以发现,如何让当前方向上面的链接。因此,每个方向变化,请致电上述code来清理位图。

现在,当我们检查的logcat,总有一个日志过来说GC_,但我不明白这一点,所以 我发现了一个惊人的文档上的内存泄漏问题:的http:// codelog.dexetra.com /越来越全能,Android的内存布鲁斯

以上链接是你的问题非常有用的。

现在,当在你的应用程序发生内存泄漏的OOME,所以要检查,请安装垫蚀。 http://www.eclipse.org/mat/downloads.php

它有点复杂的软件,但是当你通过它,你就会明白,它的pretty的实用软件。

即使这不解决您的问题,使用的WeakReference 为位图。

请参阅此链接:<一href="http://stackoverflow.com/questions/3243215/how-to-use-weakreference-in-java-and-android-development">How在Java和Android开发中使用的WeakReference?

如果我得到了解一些更多的信息,我会更新这个帖子。

请更新您的文章,如果你得到解决您的问题。

感谢您:)

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(), 
                    ChartProperties.getChartHeight(),
    Bitmap.Config.RGB_565);

    imageCache.put(String.valueOf(LandscapeChartActivity.getActiveFeature()),
                    new SoftReference(bitmap));

    if(imageCache != null){

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

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

        }
        Runtime.getRuntime().gc();
        imageCache.clear();
        imageCache = null;

解决方案

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: http://codelog.dexetra.com/getting-around-android-memory-blues

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: http://www.eclipse.org/mat/downloads.php

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.

Thank you :)

这篇关于位图的大小超过VM预算错误的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆