Why is my android app using so much memory at startup

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-03 20:28:14

问题


I have been looking into a memory leak issue for a while.

I found a cover flow on the internet from http://www.inter-fuser.com/2010/02/android-coverflow-widget-v2.html

Now I was under the impression this app was causing my outofmemory issues, and its still possible that it has something to do with it. However, I have deleted everything from my application except the splash screen. There are no other activities. and it does Nothing......

The initial intent loads the Splash Screen activity.

My application is using between 79 and 83 percent of my available heap. The phone has given me 2.816M and i have apparently allocated 2.278M this last run.

First off, 3M of available space to run an app seems like not a lot. However 2.2M loaded into memory at initial boot seems like a ton of memory consumed when the only thing I am doing is loading a single activity with an imageview pointed to an icon resource measured at around 4k......

How/Why is my app using so much memory for nothing, and how can I alleviate my 80% memory consumption at boot.

I am developing on a T-Mobile G2 and I have nothing running except this app and the default services that run on a droid.

here is some of my memory dump info

suspect 1

2,239 instances of "java.lang.Class", loaded by "<system class loader>" occupy 673,760 (35.83%) bytes.

Biggest instances:

class com.ibm.icu4jni.util.Resources$DefaultTimeZones @ 0x401dc878 - 166,600 (8.86%) bytes.
class android.text.Html$HtmlParser @ 0x4010de58 - 126,592 (6.73%) bytes.
class org.apache.harmony.security.fortress.Services @ 0x4007fd98 - 51,456 (2.74%) bytes.
class android.content.res.Resources @ 0x4004bb78 - 38,768 (2.06%) bytes.
class com.abc.AppData @ 0x44d1e040 - 26,872 (1.43%) bytes.


Keywords
java.lang.Class

suspect 2

7,072 instances of "java.lang.String", loaded by "<system class loader>" occupy 435,560 (23.16%) bytes. 

Keywords
java.lang.String

suspect 3

58 instances of "org.bouncycastle.jce.provider.X509CertificateObject", loaded by "<system class loader>" occupy 289,288 (15.38%) bytes. These instances are referenced from one instance of "java.util.Hashtable$HashtableEntry[]", loaded by "<system class loader>"

Keywords
org.bouncycastle.jce.provider.X509CertificateObject
java.util.Hashtable$HashtableEntry[]

as you can see the system appears to be loading up and using all of the memory I have been given. How can I get it to give me more memory. 3 megs is not very much to work with. and I am trying to show an image gallery.


回答1:


I have run into memory leaks in the past but not with android. In the past I used the eclipse memory analyzer tool (second link) which I found very useful. To use it you need to generate a heap dump file (or memory snapshot), the blog post tells you how to do this (first link).

http://www.andorfi.net/2011/03/memory-analysis-for-android-applications/

http://www.eclipse.org/mat/




回答2:


Debug and logging tips may help offer some insight.

https://market.android.com/details?id=org.jtb.alogcat

http://developer.android.com/guide/developing/debugging/index.html



来源:https://stackoverflow.com/questions/5682056/why-is-my-android-app-using-so-much-memory-at-startup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!