We have an Android hardware/software combo that we install at client sites.
On certain tablets, the memory starts running low, and Android starts doing its thing by killing our app, which is then automatically restarted by our watchdog service.
Here is the code we use to monitor per-app memory usage
:
for( RunningAppProcessInfo info : am.getRunningAppProcesses() ) {
int memused = am.getProcessMemoryInfo(
new int[]{info.pid})[0].getTotalPss();
Log.log(DIAG_INFO, "Process Mem: " + info.processName, memused);
}
Here is the code that gets us overall system memory levels
MemoryInfo mi = new MemoryInfo();
am.getMemoryInfo(mi);
long availableMegs = mi.availMem / 1048576L;
long threshold = mi.threshold /1048576L;
availableMegs
drops to near the threshold
(64mb in our case) and android starts killing stuff.
But, when we look at the per-process memory usage, add up the TotalPss
values, we get a normal total. No process that is out of control memory-wise!
Any ideas where the missing RAM has gone?
Have you used an external tool such as the Eclipse Memory Analyzer (MAT)? It might give you a better perspective than your in-app measurements. It's not hard to use, but does require a bit of setup. Here's a pretty good write-up of its usage.
A solution that reports memory across all apps on the device is in the Eclipse System Information view. To use it, open the DDMS
perspective and select a device in the Devices
view. Then open the System Information
view and select Memory usage
in the left drop-down. You can get a snapshot of memory used across the device each time you click on Update from Device
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With