java.lang.OutOfMemoryError:位图大小超过VM预算 - 机器人 [英] java.lang.OutOfMemoryError: bitmap size exceeds VM budget - Android

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

问题描述

我开发了使用大量的图像在Android上的应用程序。

I developed an application that uses lots of images on Android.

该应用程序运行一次,填补了信息在屏幕上(布局列表视图 Textviews ImageViews 等),用户读取的信息。

The app runs once, fills the information on the screen (Layouts, Listviews, Textviews, ImageViews, etc) and user reads the information.

没有动画,没有什么特别的效果或任何可以填充内存。 有时,可绘制可以改变。有些是Android的资源,有些是保存在文件夹中的SD卡文件。

There is no animation, no special effects or anything that can fill the memory. Sometimes the drawables can change. Some are android resources and some are files saved in a folder in the SDCARD.

然后在用户退出(即的onDestroy 的方法执行,应用程序的虚拟机保留在内存中),然后在某个时候用户再次输入。

Then the user quits (the onDestroy method is executed and app stays in memory by the VM ) and then at some point the user enters again.

每个用户输入到应用程序的时候,我可以看到内存变得越来越多,直到用户获取 java.lang.OutOfMemoryError

Each time the user enters to the app, I can see the memory growing more and more until user gets the java.lang.OutOfMemoryError.

那么,什么是最好的/正确的方式来处理大量图像?

So what is the best/correct way to handle many images?

我应该把它们放在静态方法,因此不会加载所有的时间? 我一定要使用干净的布局以特殊的方式布局或图像?

Should I put them in static methods so they are not loaded all the time? Do I have to clean the layout or the images used in the layout in a special way?

推荐答案

这听起来像你有内存泄漏。这个问题不处理的画面,那就是你的图像没有得到释放,当你的活动被销毁。

It sounds like you have a memory leak. The problem isn't handling many images, it's that your images aren't getting deallocated when your activity is destroyed.

这是很难说这是为什么不看你的code。但是,这篇文章有一些技巧,可以帮助:

It's difficult to say why this is without looking at your code. However, this article has some tips that might help:

<一个href="http://android-developers.blogspot.de/2009/01/avoiding-memory-leaks.html">http://android-developers.blogspot.de/2009/01/avoiding-memory-leaks.html

在特定的,使用静态变量很可能使事情变得更糟,而不是更好。您可能需要增加code,消除回调,当你的应用程序重绘 - 但同样,有没有足够的信息在这里肯定地说。

In particular, using static variables is likely to make things worse, not better. You might need to add code that removes callbacks when your application redraws -- but again, there's not enough information here to say for sure.

这篇关于java.lang.OutOfMemoryError:位图大小超过VM预算 - 机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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