Look at ActivityManager, it has access to memory info. I bet you could use that to manage/find memory leaks and other things.
Let me know if that helps at all! On Tue, Apr 21, 2009 at 8:57 AM, Richard Cook <[email protected]>wrote: > This is a good question, a proper testing method for unit power/memory > consumption. I believe there is one through instrumentation that allows you > to access the free memory (I can't find it right now). > > But I'd like to know this as well. > > > On Tue, Apr 21, 2009 at 3:18 AM, Mariano Kamp <[email protected]>wrote: > >> Hi, >> >> I sometimes get bug reports that are caused by an OutOfMemory error. It >> happens when creating a bitmap, but I am pretty sure that it is not the >> bitmap size that is the real problem, because the instantiation of those >> images happens > 100.000 times a day without an error report. Those png >> images are of 4K size (on disk) anyway. >> >> Those bug reports are very infrequent, but still I would love to get rid >> of them. I can't reproduce the memory growing over 10 MBs (actually way >> less) when using the app myself and monitoring the memory consumption in >> DDMS. I also, at no point in time, cache something or hold on to more than >> one item (article in my case) at a time, except in one list. There the list >> caches the visible components, which cannot amount to much too and is >> default functionality from the Android framework. >> >> I meanwhile kind of ***suspect*** that maybe the WebView I embed does >> eat up all the memory, because the page to display might be huge?! I don't >> know though how to get closer to confirming that or any other possible >> cause. I tried to use a ca. url that one user provided me with, but this >> also didn't make the memory grow much. And a single page it is probably not >> a good enough test case, as it doesn't account for what page was displayed >> before and how the cache behaved. >> >> So I would like to gather more data when I capture an OutOfMemory and >> create a bug report. >> >> The obvious thing would be to include the current memory consumption. >> >> Something like this? >> >> Runtime rt = Runtime.getRuntime(); >> >> Log.d("Memory", "Memory left=" >> >> + String.format("Memory free: %4.2fMB total: %4.2fMB max: %4.2fMB", >> >> rt.freeMemory() / 1024 / 1024.0, >> >> rt.totalMemory() / 1024 / 1024.0, >> >> rt.maxMemory() / 1024 / 1024.0)); >> >> Memory left=Memory free: 3.94MB total: 6.82MB max: 16.00MB (see >> screenshot for DDMS at the same point in time) >> >> I am not sure though, if this of any value. When I get an OutOfMemory >> error I would *expect* to get free: 0, total: 16, max 16. >> I would still deploy that in a new version, just in case. Maybe my process >> didn't even get 16 MB, because the phone was running low on memory as it is? >> >> Anything else I can measure of gather to get to the bottom of it? >> >> Cheers, >> Mariano >> >> -- Android Version: sdk=2, release=1.1, inc=128600 >> -- Thread State: RUNNABLE >> -- NewsRob Version: 1.9.0/190 >> -- Stacktrace: >> java.lang.RuntimeException: Unable to start activity >> ComponentInfo{com.newsrob/com.newsrob.ShowEntryActivity}: >> android.view.InflateException: Binary XML file line #29: Error inflating >> class java.lang.reflect.Constructor >> at >> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2141) >> at >> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2157) >> at android.app.ActivityThread.access$1800(ActivityThread.java:112) >> at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1581) >> at android.os.Handler.dispatchMessage(Handler.java:88) >> at android.os.Looper.loop(Looper.java:123) >> at android.app.ActivityThread.main(ActivityThread.java:3739) >> at java.lang.reflect.Method.invokeNative(Native Method) >> at java.lang.reflect.Method.invoke(Method.java:515) >> at >> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739) >> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497) >> at dalvik.system.NativeStart.main(Native Method) >> Caused by: android.view.InflateException: Binary XML file line #29: Error >> inflating class java.lang.reflect.Constructor >> at android.view.LayoutInflater.createView(LayoutInflater.java:512) >> at >> com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) >> at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:562) >> at android.view.LayoutInflater.rInflate(LayoutInflater.java:617) >> at android.view.LayoutInflater.inflate(LayoutInflater.java:407) >> at android.view.LayoutInflater.inflate(LayoutInflater.java:320) >> at android.view.LayoutInflater.inflate(LayoutInflater.java:276) >> at >> com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:231) >> at android.app.Activity.setContentView(Activity.java:1569) >> at com.newsrob.ShowEntryActivity.onCreate(ShowEntryActivity.java:70) >> at >> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1122) >> at >> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2104) >> ... 11 more >> Caused by: java.lang.reflect.InvocationTargetException >> at android.widget.Button.<init>(Button.java:63) >> at java.lang.reflect.Constructor.constructNative(Native Method) >> at java.lang.reflect.Constructor.newInstance(Constructor.java:424) >> at android.view.LayoutInflater.createView(LayoutInflater.java:499) >> ... 22 more >> Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget >> at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) >> at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:290) >> at android.graphics.drawable.Drawable.createFromStream(Drawable.java:635) >> at android.content.res.Resources.loadDrawable(Resources.java:1454) >> at android.content.res.Resources.getDrawable(Resources.java:498) >> at >> android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:143) >> at >> android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:716) >> at android.graphics.drawable.Drawable.createFromXml(Drawable.java:667) >> at android.content.res.Resources.loadDrawable(Resources.java:1439) >> at android.content.res.TypedArray.getDrawable(TypedArray.java:520) >> at android.view.View.<init>(View.java:1693) >> at android.widget.TextView.<init>(TextView.java:231) >> at android.widget.Button.<init>(Button.java:67) >> ... 26 more >> >> >> >> > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

