如何确定我的 android 应用程序是否存在内存泄漏?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11064940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I determine if my android app has memory leak?
提问by Alex Kapustian
I look all over the internet\goolge\stackoverflow and couldn't find full and simple guide that can explain to me how can I find if my android app has a memory leak. Can anyone explain to me how to do it, or even better give me good guide for it?
我查看了整个 Internet\goolge\stackoverflow,但找不到完整而简单的指南来向我解释如何找到我的 android 应用程序是否存在内存泄漏。任何人都可以向我解释如何做到这一点,或者更好地为我提供很好的指导?
My app collecting data about the battery and saves it to DB on the phone. Each time that their is a change in the battery (ACTION_BATTERY_CHANGED) I check if the battery precentage changed and in this case I save some data.
我的应用程序收集有关电池的数据并将其保存到手机上的数据库中。每次他们的电池发生变化(ACTION_BATTERY_CHANGED)时,我都会检查电池百分比是否发生变化,在这种情况下我会保存一些数据。
This app takes (25-30)MB RAM I think that this is too much for such simple app.I suspect that it has a memory leak.
这个应用程序需要 (25-30)MB RAM 我认为这对于这样简单的应用程序来说太多了。我怀疑它有内存泄漏。
采纳答案by Dheeresh Singh
You can use MAT
您可以使用 MAT
It is a very good tool and gives very detailed report of your project with basic information linked with memory leaks
这是一个非常好的工具,可以提供非常详细的项目报告,其中包含与内存泄漏相关的基本信息
MAT in Android
Android 中的 MAT
http://android-developers.blogspot.in/2011/03/memory-analysis-for-android.html
http://android-developers.blogspot.in/2011/03/memory-analysis-for-android.html
How to use MAT
如何使用垫子
http://kohlerm.blogspot.in/2009/07/eclipse-memory-analyzer-10-useful.html
http://kohlrm.blogspot.in/2009/07/eclipse-memory-analyzer-10-useful.html
http://android-developers.blogspot.in/2011/03/memory-analysis-for-android.html
http://android-developers.blogspot.in/2011/03/memory-analysis-for-android.html
http://ttlnews.blogspot.in/2010/01/attacking-memory-problems-on-android.html
http://ttlnews.blogspot.in/2010/01/attacking-memory-problems-on-android.html
Eclipse integration of MAT
MAT 的 Eclipse 集成
http://www.eclipse.org/mat/downloads.php
http://www.eclipse.org/mat/downloads.php
http://www.eclipse.org/forums/index.php/m/878338/
http://www.eclipse.org/forums/index.php/m/878338/
Update Site: http://download.eclipse.org/mat/1.1/update-site/
更新站点:http: //download.eclipse.org/mat/1.1/update-site/
Eclipse integration of BERT (dependency on this )
BERT 的 Eclipse 集成(依赖于此)
http://wiki.eclipse.org/BIRT_Update_Site_URL
http://wiki.eclipse.org/BIRT_Update_Site_URL
http://download.eclipse.org/birt/update-site/3.7-interim
http://download.eclipse.org/birt/update-site/3.7-interim
回答by Vladimir Tchernitski
When I faced the same problem as you, I found LeakCanary. It helps to detect memory leaks during runtime in debug builds and provides comfortable UI for the stacktrace history. Here you can read more information about this tool for detecting memory leaks as well as some other useful hints for Android development: http://cases.azoft.com/4-must-know-tools-for-effective-android-development/. Hope it works for you and other mobile developers!
当我遇到和你一样的问题时,我找到了LeakCanary。它有助于在调试版本的运行时检测内存泄漏,并为堆栈跟踪历史提供舒适的 UI。在这里,您可以阅读有关此用于检测内存泄漏的工具的更多信息以及其他一些对 Android 开发有用的提示:http: //cases.azoft.com/4-must-know-tools-for-effective-android-development/. 希望它适用于您和其他移动开发人员!
回答by sivi
Generally if you use an application and it's accumulating memory
通常,如果您使用应用程序并且它正在累积内存
12 MB ... 13.5 MB...15 MB ... think about a cloud that accumulates humidity ... etc
12 MB ... 13.5 MB...15 MB ... 想想积聚湿气的云...等等
If you see this pattern than your app has memory leak.
如果您看到此模式,则说明您的应用程序存在内存泄漏。
Another possibility is that you don't have a leak but you just use too many objects or too big objects or that you do not economize objects well enough. take under account that bitmaps are very expensive so handling bitmaps may not be so trivial in android which is memory and resource limited environment.
另一种可能性是您没有泄漏,但您只是使用了太多的对象或太大的对象,或者您没有足够好地节约对象。考虑到位图非常昂贵,因此在内存和资源有限的 android 环境中处理位图可能不是那么简单。