In the case of Android memory optimization, we are not able to use large memory.
So sometimes it's worth knowing how much memory our app occupies and how much memory it takes.
At this time, Android's DDMS provides a tool to see the memory usage of the app while it's running.
Let me take Android studio for example. Eclipse ADT is actually the same.
This is also the icon in Eclipse.
How to use it has been shown clearly in the figure.
1. Find the currently running phone
2. Click on the process with the same package name as your app
3, click Update Heap
4. Switch to the heap view and click the Cause GC button
5. Click the app process according to your needs
6, the histogram in the graph is the memory usage of your app.
We can lock down the areas that should be optimized based on how the memory is being used.
Precautions :
1,cause GC button Click once is equivalent to the virtual machine requesting a GC operation
2, when the memory information is displayed, there is no need to click the Cause GC button again. The heap view is refreshed periodically, and the corresponding operating procedure shows memory changes.
How do I know about program memory leaks?
A row of data in the heap view is called data object. It is an object of a large number of class types that exist in our app.
In the data object, there is a column total Size, whose value is the amount of memory for all Java objects in the current process.
In general, this value determines whether a memory leak occurs.
How to judge?
1. Continue to operate your app while observing the value of total size.
The value of 2,total size generally stabilizes within a normal range.
3, when we are constantly operating the app, the memory will have a first increase (constantly generated objects), and then drop (object is recycled). If the code of the program is handled well, then the memory footprint will have a noticeable drop and stabilize at a normal level.
4, if your code does not release memory very well. Then, the memory footprint does not have a noticeable fall, and will become higher and lower, eventually reaching the upper limit program was killed.
how to deal with?
What do we need to do when we find a memory leak?
In general, we are familiar with the code we write, we can judge according to logic, where the current operation is causing a memory leak. Then analyze, modify.
But if you change someone else's code, it drives you crazy. Here is a tool: The Memory Analyzer Tool Mat, which can be used as a plugin in eclipse. Android Studio I haven't tried it yet. But there are clients.
and usage details see: Www.eclipse.org/mat
from:http://blog.csdn.net/yehui928186846/article/details/51387079
"Go" Android ide--through DDMS to see the memory of the app running