Android应用程序的内存不足的问题 - 什么都试过了,仍然处于亏损状态 [英] Android app out of memory issues - tried everything and still at a loss

查看:206
本文介绍了Android应用程序的内存不足的问题 - 什么都试过了,仍然处于亏损状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了4个全日试图尽我所能找出一个应用程序我开发的内存泄漏,但事情停止决策意识是很久以前的。

I spent 4 full days trying everything I can to figure out the memory leak in an app I'm developing, but things stopped making sense a long time ago.

该应用程序我开发是社会性的,所以个人认为型材活动(P),并列出活动的数据 - 例如徽章(B)。您可以从轮廓跳到徽章名单等资料,到其他列表等。

The app I'm developing is of social nature, so think profile Activities (P) and list Activities with data - for example badges (B). You can hop from profile to a badge list to other profiles, to other lists, etc.

想象一下这样的P1流 - > B1 - > P2 - > B2 - > P3 - > B3等为保持一致,我加载配置文件和同一用户的徽章,让每个P页面是一样的所以是每个B页面。

So imagine a flow like this P1 -> B1 -> P2 -> B2 -> P3 -> B3, etc. For consistency, I'm loading profiles and badges of the same user, so each P page is the same and so is each B page.

问题的一般要点是:浏览了一下,根据每个页面的大小后,我得到了内存不足的异常随机的地方 - 位图,字符串,等等 - 这似乎并没有是一致的。

The general gist of the problem is: after navigating for a bit, depending on the size of each page, I get an out-of-memory exception in random places - Bitmaps, Strings, etc - it doesn't seem to be consistent.

尽一切可以想象弄清楚为什么我运行内存后,我想出了什么。我不明白的是为什么Android的,如果它运行的时加载内存,而是崩溃不杀P1,B1等。我希望这些早期的活动呀,通过的onCreate()和onRestoreInstanceState()。如果我被复活以往任何时候都还给他们。

After doing everything imaginable to figure out why I am running out of memory, I have come up with nothing. What I don't understand is why Android isn't killing P1, B1, etc if it runs out of memory upon loading and instead crashes. I would expect these earlier activities to die and be resurrected if I ever Back to them via onCreate() and onRestoreInstanceState().

让独此 - 即使我做P1 - > B1 - >返回 - > B1 - >返回 - > B1,我仍然得到崩溃。这表明某种类型的内存泄漏,但即使在反倾销HPROF和使用MAT和JProfiler的,我不能找出它。

Let alone this - even if I do P1 -> B1 -> Back -> B1 -> Back -> B1, I still get a crash. This indicates some sort of a memory leak, yet even after dumping hprof and using MAT and JProfiler, I can't pinpoint it.

我已经从网络上禁用加载图像的(并增加了装来弥补它,使测试公正的测试数据),并确保图像缓存使用SoftReferences。机器人实际上是尝试腾出几SoftReferences有,但在此之前右崩溃的内存不足。

I've disabled loading of images from the web (and increased the test data loaded to make up for it and make the test fair) and made sure the image cache uses SoftReferences. Android actually tries to free up the few SoftReferences it has, but right before it crashes out of memory.

徽章的网页从Web数据,将其加载到EntityData从一个BaseAdapter数组并喂到ListView(我实际使用CommonsWare的的优秀MergeAdapter ,但在这个徽章的活动,有真的只有1适配器反正,但我想提及这个事实,无论哪种方式)。

Badge pages get data from the web, load it into an array of EntityData from a BaseAdapter and feed it to a ListView (I'm actually using CommonsWare's excellent MergeAdapter, but in this Badge activity, there is really only 1 adapter anyway, but I wanted to mention this fact either way).

我已经通过了code走了,没能找到任何可能泄漏。我清了清喉咙调零了所有我能找到,甚至System.gc()的左,右,但仍应用程序崩溃。

I've gone through the code and was not able to find anything that would leak. I cleared and nulled everything I could find and even System.gc() left and right but still the app crashes.

我还是不明白,为什么不活动是在栈上的活动没有得到收获,我真的很想弄清这一点。

在这一点上,我正在寻找任何提示,建议,解决方案......任何可能的帮助。

At this point, I'm looking for any hints, advice, solutions... anything that could help.

感谢你。

推荐答案

一那的的事情真的的帮助结束了被设置inPurgeable为真为我的位图在我的情况下,内存问题。请参阅<一href="http://stackoverflow.com/questions/7068132/why-would-i-ever-not-use-bitmapfactorys-inpurgeable-option">Why我会永远不得使用BitmapFactory的inPurgeable选项?与答案的讨论以获得更多信息。

One of the things that really helped the memory issue in my case ended up being setting inPurgeable to true for my Bitmaps. See Why would I ever NOT use BitmapFactory's inPurgeable option? and the answer's discussion for more info.

戴安娜Hackborn的答案,我们随后的讨论(也感谢,CommonsWare)有助于澄清一些事情,我很困惑,所以谢谢你。

Dianne Hackborn's answer and our subsequent discussion (also thanks, CommonsWare) helped clarify certain things I was confused about, so thank you for that.

这篇关于Android应用程序的内存不足的问题 - 什么都试过了,仍然处于亏损状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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