Is there something in Eclipse or possibly a 3rd party tool that lets me see how my app is using up memory while it is running? When my app runs, there appears to be something that over time starts eating up memory. It would be nice to see what class is responsible for it so that I can zoom in on the area that is causing the problem. It would be nice to see how memory is being used dynamically over time and what know what classes/methods are "leaking".
Traceview is there for the rescue. See the official documentation http://developer.android.com/tools/debugging/debugging-tracing.html .
You can check the memory leaks through it too. DDMS provides a UI for profiling also.
Related
My customer raise a problem about our app which is the app is getting slower when using for long time, but our side cannot simulate the problem as we are not in their real working environment, we are not able to solve the problem before knowing the bug. anyone can help?
If it´s a issue that raises "by the passing of time", you should look for any task you might be running and repeating itself.
You should check the different types of functionalities you use.
For example, if your app it´s using a local database:
Look for unclosed cursors.
I/O work
If your are using animations:
Look for skipped frames
Complex view hierarchies
If using background tasks or threading:
I/O work
Unfinished threads
Increasing thread number
If using networking and Webservices:
Problems with your server database
Connection issues
Proxys
...
You could also use something like Firebase + Crashlytics to see if theres any warning raises but gets silently disposed.
Giving some more info about your app and what it does could be useful for elaborating more accurate solution.
A common source of slowing down apps is memory leaks.
on iOS what you can do is to activate Memory management flags on your target and keep a watch on the logs, you can also use Xcode Memory Graph and instruments leak tools to detect leaks.
on Android you can use tools like LeakCanary to be notified when leaks happens.
Once you have a leak detected you can inspect your code to identify the source and better manage memory.
#axierjhtjz mention lots of good starting points.
Does it occur on both iOS and Android, specific devices, vendors?
If it is mainly on a single platform (Android/iOS), on different devices and the main complaint is slowness over time, I would suspect the following:
Memory leak (maybe UI, fragments)
Data persistent data incremental over time or/and more IO operation over time.
If you unable to debug the problem on the customer site, I would suggest to add a remote real time monitoring capabilities over relevant parameters and logs.
A good tool we used in the past was TestFairy. maybe they have a free trial
I have a simple application that contains two implementations which I want to compare(benchmark) with each other in terms of usage during a certain amount of time.
The testing method is equal for both implementations (they both execute exactly the same commands/events) the only difference is the way they process the command and events.
I wish to get a log per second of:
CPU load
Memory usage
Network traffic
The Android Monitor provides everything I need in a graph and logs per second the current CPU load, Memory usage and the TX/RX for network traffic, great!
However I wish to have this all in a text log instead of a live graph. Can someone tell me where I could find such a log? OR if there is no such thing, any suggestions to get similar data?
Doppie, I looked for a solution using out-of-box tools, but there is no good way to use the Android tools to export just the information you want to a text file without lots of work. Logcat is way too verbose and requires conversion, and Dalvik doesn't exactly provide you the every-second control over data collection. I would love to have a simple solution for this too. :/
[Disclaimer: Because I work with Perfecto, I know that the devices in their cloud lab can do this easily, so if you are trying to diagnose a specific problem, you could use their free public cloud and export the device vitals (shown below). This is not a pitch, but since it's free to play, it might help you in the short-term.]
hi first of all if you looking for memory logs. There is one option you can directly go and check that one.
Open Android Device Monitor then checks heap dumps.Check the uses of memory.
Another way to monitor Android Device Monitor then see the Allocation Tracker it gives you details in everyclass where you memory is used.
Expect these things you can directly check your Current logs.
Click Android Monitor and see logcat and second option Monitors.
Monitors gives you Four type of details :
1. Memory usages.
2. CPU how kuch usages of your phone.
3. Network
4. GPU.
Now after these all things. If you still have some problem then need to check your gradle.
What kind of libraries you used.
First of all remove unwanted libraries.
Secondly need to import only useful libraries. Like if you looking for map related things in your app then import only.
compile "com.google.android.gms:play-services-maps:9.4.0"
not this one.
compile 'com.google.android.gms:play-services:9.4.0'
Aware about replication of libraries.
Example : If you using some libraries and that libaray contain appcompt and you are also using same libaray in your app side.Then its better to use that libaray as module.
At last try to use proguard rules.
These are few ways to handle better memory management.
I have made one android app architecture here is link..
Thanks hope this will help you.
My app is consuming a lot of memory
I have used the following app to measure my app memory consumption
https://play.google.com/store/apps/details?id=mem.usage&hl=en
can any one tell me how can I optimize the memory used by my app?
1) you can use LeakCanry for optimize memory. leakCanry will give you report for each individual leaks or when multiple instance of an activity will be on stack.
here is more info and integration guide https://github.com/square/leakcanary
2) you can check android studio memory monitor for your app's memory use. from that graph you can check when GC is being called and which activity or function is taking more memory so you can optimize through it.
more info regarding this http://developer.android.com/tools/performance/memory-monitor/index.html
3) i have gone through udacity tutorial and videos. you can see how to improving rendering for your layouts
Need to reduce unnecessary views.
dont apply unnecessary background.
more stuff https://www.udacity.com/course/android-performance--ud825
4) one more important thing use ApplicationContext where you can use it because Activity context keeps in stack and wont be eligible for GC until that context related task is being finished.
https://developer.android.com/tools/performance/comparison.html
Start with running Memory Profiler Tool to see what is the causes that leak/consume much memory in your app.
I have an android app developed in eclipse and i need to determine whether there is any memory leak in it. I need to achieve it without using any memory leak anaylzer tools, I want to write a piece of code for checking memory leak in the app. Is it possible? Any suggestion would help me.
You're in luck, someone at Square wrote a small library that finds all activity memory leaks https://github.com/square/leakcanary. I recommend turning it on only in debug build so you can find all leaks.
Well, the title says it.
It would also be handy to know how many memory is still available.
I am writing a memory hungry application that tends to crash randomly (in native Code),
and my suspicion is that it gets out-of-memory.
I think you'd struggle to find a more comprehensive answer than this on the subject:
How do I discover memory usage of my application in Android?
i agree with hackbod's reply. As far as my understanding goes, your app wont crash , rather it will be killed.
you may find this discussion interesting
Is there a need to check for NULL after allocating memory, when kernel uses overcommit memory.
I guess there is some call back to know lowmemory conditions(onLowMemory()), you can use it to identify low memory conditions, I havent tried it though.
Applications on Android generally don't crash due to low memory. If you are using a lot of memory, you may cause most all other applications to be killed. If you keep on using memory, you may cause the system to kill your app as well (not crashing it, just killing it), though you will probably get to the point of noticeable paging before that happens.
If you are dealing with native code, the more likely explanation is that you are corrupting memory somewhere.
You might want to catch the OutOfMemoryException and then call System.gc() to perform a manual garbage collection, then retry that piece of code that failed. You might be able to use native exceptions with JNI to detect when the C++ code fails due to lack of memory, or anticipate.
Check http://kohlerm.blogspot.com/2010/02/android-memory-usage-analysis-slides.html to find out which java objects use the most memory