简体   繁体   English

位图大小超过Vm预算错误android

[英]bitmap size exceeds Vm budget error android

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. 当我滚动另一个对象被调用并显示其位图时,当我反复这样做时,位图大小超过vm预算错误,我已经做了所有的事情,如recycle() ,设置null然后调用GC() ,我还有同样的错误。 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. 由于位图,我也有同样的问题OOME。

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. 当方向从PORTRAIT更改为LANDSCAPE(反之亦然)时,先前的UI将被完全丢弃,并且会加载并显示新的UI。在这种情况下,如果您在应用中使用了许多位图,则需要在适当的位置发布它们。

To check the orientation of your device, please see this: Check orientation on Android phone 要查看设备的方向,请参阅: 在Android手机上查看方向

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 现在,当我们检查logcat时,总会有一个日志出现在说GC_,但我无法理解,所以我发现了一个关于内存泄漏问题的惊人文档: http//codelog.dexetra.com/getting-around- Android的内存布鲁斯

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. 现在,当您的应用程序中存在内存泄漏时,OOME会发生。所以要检查一下,请安装MAT for eclipse。 You can find it at: http://www.eclipse.org/mat/downloads.php 您可以在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. 即使这不能解决您的问题,也可以使用WeakReference作为位图。

Please refer this link: How to use WeakReference in Java and Android development? 请参考此链接: 如何在Java和Android开发中使用WeakReference?

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 :) 谢谢 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM