Android的虚拟机内存不足错误 [英] Android VM Out of Memory Error

查看:159
本文介绍了Android的虚拟机内存不足错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/2928002/outofmemoryerror-bitmap-size-exceeds-vm-budget-android\">OutOfMemoryError:位图大小超过VM预算: - Android电子

我上下研究这个问题,我找不到我的特定问题什么。我使用位于我绘制文件夹按钮背景的.png文件。这些按钮是大(约150P×150 P)和使用图像和gradiants看起来不错。背景在pressing按钮作为单独的.xml文件中定义的改变。我在谷歌找到的解决方案似乎是对于在布局指定称为programmaticly,而不是图像的图像。当我不断地退出和进入不同的布局和不同的按钮不同的活动,我将最终得到内存不足的错误

I've researched this problem up and down and I can't find anything about my specific problem. I use .PNG files located in my drawable folder for button backgrounds. The buttons are large (about 150p x 150 p) and use images and gradiants to look nice. The backgrounds change upon pressing the button as defined in individual .xml files. The solutions i find in google seem to be for images called programmaticly and not images that are specified in layouts. When I constantly exit and enter different activities with different layouts and different buttons I will eventually get the out of memory error

04-27 22:18:46.227:E / dalvikvm堆(512):396900字节外部分配太大,这一进程

04-27 22:18:46.227: E/dalvikvm-heap(512): 396900-byte external allocation too large for this process.

04-27 22:18:46.427:E / AndroidRuntime(512):java.lang.OutOfMemoryError:产生的原因位图的大小超过VM预算

04-27 22:18:46.427: E/AndroidRuntime(512): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget

我的问题是我怎么分配的时候我的图片布局指定更多的内存,并且不添加programaticlly?

My question is how do I allocate more memory when my images are specified in layouts and are not added programaticlly?

推荐答案

以下能搞清楚帮助到底是什么你的记忆:

The following can help in figuring out what's eating your memory:

添加的UncaughtExceptionHandler 当你拿到OOM异常转储堆。使用<一个href=\"http://developer.android.com/reference/android/os/Debug.html#dumpHprofData%28java.lang.String%29\"相对=nofollow> Debug.dumpHprofData()转储堆。在此之后,您将文件转换与 HPROF-CONV ,并检查生成的文件使用 Eclipse的内存分析器

Add an UncaughtExceptionHandler and dump the heap when you get the OOM Exception. Use Debug.dumpHprofData() to dump the heap. After this, you convert the file with hprof-conv and check the resulting file using Eclipse Memory Analyzer.

当心在UncaughtExceptionHandler的包裹例外,有时OOM异常被包裹在一个RuntimeException。

Watch out for wrapped exceptions in the UncaughtExceptionHandler, sometimes the OOM Exception is wrapped in a RuntimeException.

这篇关于Android的虚拟机内存不足错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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