位图的大小超过VM预算错误的android位图、预算、大小、错误

由网友(你是我命中的劫)分享简介:当我改变为横向模式,几个对象都与全屏位图创建。当我滚动其他对象称为其位图显示,当我做这个反反复复,位图的大小超过 VM 预算错误,我已经做了所有的事情一样循环(),设置为空值,然后叫 GC(),我仍然有同样的错误。创建位图.... 位= Bitmap.createBitmap(ChartProperties.getCh...

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

当我滚动其他对象称为其位图显示,当我做这个反反复复,位图的大小超过 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;
 
给新人主播一些OBS设置建议,让你的直播间画质提升个数量级

解决方案

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

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

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

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

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

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

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

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

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

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

请参阅此链接: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 :)

阅读全文

相关推荐

最新文章