The Android side can obtain the memory information directly through the ADB command, of course, Android Studio also provides the memory of the Monitoring Analysis tool, and later can be combined with mat analysis
Today is a way to analyze with the Android Studio and Mat tools:
1 . After packaging through Android studio, the app installs successfully
2. Click on Android Monitor to see:
After running the app successfully, you can see that the app's process has started, and then you can manipulate and observe the data.
See the data that can be monitored in Android Monitor: CPU, memory, network, and GPU
3. Check the memory column:
See the 5s as the interval, the graph will always change, where the dark blue represents the assigned, light blue represents the free
Repeated operations, such as entering the app and then exit normally, observe the memory data, if the memory has been growing, you can initially determine that there may be a problem
Click on the truck below, force the GC, then click the first icon in the back of the truck, and after you put the mouse on it, you can see tips for the dump Java heap,
A hprof file will then be generated, see:
You can then click Analyzer Tasks to expand the analyzer tasks,
After that, you can see the diagram below and tick the two items below the analyzer tasks, respectively, to detect leaked activities and find Duplicate Strings
Then click on the right green triangle button to get the results, click Expand leaked activities, you can see the leaked activity object
You can then use the Mat tool to convert the Hprof file and analyze it with the mat tool;
The address of the Hprof file is in the captures directory of the project directory
Locate the file, format the file, and convert it through the Platform-tools/hprof-conv.exe in the SDK tool:
via cmd command line: Hprof-conv from.hprof to.hprof
The resulting hprof file can then be opened with the mat, and more specific analysis can be found below the data content:
Memory analysis, in fact, is not necessarily a memory leak will be a problem, memory leak refers to some of the objects are still not released after forcing the GC, but the program itself, the object of the application space is relatively large, or multiple operations are always not released, this will also cause problems.
Some scenarios where memory problems are prone to occur:
1, there are many pictures of the page, or need to apply for a larger space (such as switching tab)
2, the existence of the ListView page, ListView reuse and timely release, etc.
3, the activity does not change the page, but the data will not change the new logic
"Android App memory Analytics" uses tools for memory analysis of apps