Android的正在运行的应用的内存使用情况 [英] Android Running apps memory usage

查看:95
本文介绍了Android的正在运行的应用的内存使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是堆的使用量(分配),我们可以在Elipse内存分析工具看到(在DDMS视图)和这里显示的Andr​​oid设备?:

What is the difference between the heap usage (Allocated) we can see in the Elipse Memory Analysis Tool (in the DDMS view) and the memory usage size for the same App shown here on the Android device?:

设置 - > 应用 - > 运行

Settings->Apps->Running

尽管我积极地使对象只要是没有必要,他们空试图preserve内存,后者号(上运行的应用程序的屏幕内存使用的大小)只有持续上升,我的应用程序崩溃最终由于OutOfMemoryError异常。然而,前者向我表明我还有一个合理的规模内。我也调用System.gc()了很多。有两者之间的差异?为什么不一致?我如何能解决这个问题的任何想法?

Even though I aggressively tried to preserve memory by making objects null as soon as they weren't needed, the latter number (memory usage size on Running apps screen) only kept increasing and my app finally crashed due to OutOfMemoryError. However, the former showed me that I was well within a reasonable size. I was also calling System.gc() a lot. Is there a difference between the two? Why the discrepancy? Any ideas on how I can solve this problem?

推荐答案

二,我所知道的最大的区别是垃圾收集的范围。

The biggest difference between the two that I know of is the scope of garbage collection.

普通垃圾收集,包括的System.gc(),收集了一下垃圾,然后停止。这不是堆的完整扫摆脱一切。那就是尽量减少垃圾收集的CPU的影响

Normal garbage collection, including System.gc(), collects a bit of garbage, then stops. It is not a complete sweep of the heap to get rid of everything. That is to try to minimize the CPU impact of garbage collection.

堆转储prepared为MAT,虽然实际上是一个完整的GC。

The heap dump prepared for MAT, though, effectively a complete GC.

您的症状建议你比GC更快的内存分配可以收回它。它的基本方法是尽量少分配内存,或不常分配它。例如,在可能情况下,重用对象,位图缓存等,而不是试图让GC清理旧东西,你去分配新的东西。

Your symptoms suggest that you are allocating memory faster than GC can reclaim it. The primary solution for this is to try to allocate less memory, or allocate it less frequently. For example, where possible, reuse objects, bitmap buffers, and the like, instead of trying to let GC clean the old stuff and allocating new stuff as you go.

这篇关于Android的正在运行的应用的内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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