1. Code to obtain the current app memory usage
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
//Maximum allocated memory
int memory = ();
("memory: "+memory);
//Maximum allocated memory acquisition method 2
float maxMemory = (float) (().maxMemory() * 1.0/ (1024 * 1024));
//The total memory currently allocated
float totalMemory = (float) (().totalMemory() * 1.0/ (1024 * 1024));
//Remaining memory
float freeMemory = (float) (().freeMemory() * 1.0/ (1024 * 1024));
("maxMemory: "+maxMemory);
("totalMemory: "+totalMemory);
("freeMemory: "+freeMemory);
result
: memory: 256
: maxMemory: 256.0
: totalMemory: 11.974937
: freeMemory: 3.6257935
This shows that the maximum allocated memory of my app on the mobile phone is 256m, and now it has allocated 11m. 6m of these 11m are free.
Of course, Monitors can view memory usage more intuitively
2. Use the dos command
(1) Open the dos window and execute the adb shell
(2) dumpsys meminfo package name
result:
3. Use Monitors or DDMS
monitors
DDMS
The above is all about this article, I hope it will be helpful to everyone's learning. For more tutorials, please visitCoders' Home