5

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?

Harry Mexican
  • 1,514
  • 1
  • 21
  • 51
  • You have any open connections to a database/web service of some sorts that you guys may be missing? – ksudu94 Apr 09 '14 at 16:31
  • 2
    I think the total PSS value just gives you the user-space memory usage(All the user space processes accessible by activity manager). Total memory is kernel + drivers + user processes. am.getMemoryInfo() gets the information from /proc/meminfo which is fairly accurate on the total system memory usage. Something might be actually wrong on those tabs. just a thought!! – digitizedx Apr 10 '14 at 18:01
  • 1
    i am assuming `getRunningAppProcesses()` probably doesn't return kernel or other system level memory usages. probably only on the application/dalvik level. – minhaz Apr 10 '14 at 20:06

1 Answers1

4

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.

enter image description here

scottt
  • 7,931
  • 1
  • 28
  • 39
  • Unfortunately, the units exhibiting this memory problem are at client sites, in steel enclosures, in busy spaces, so it's not straight-forward to plug them into eclipse. – Harry Mexican Apr 04 '14 at 23:04
  • 1
    There aren't nearly as many in-app tools available. The S/O question http://stackoverflow.com/questions/2298208/how-to-discover-memory-usage-of-my-application-in-android has a well-written answer that discusses memory matters. Linking from there will get you to http://developer.android.com/training/articles/memory.html and from there http://developer.android.com/tools/debugging/debugging-memory.html . Might be worth a look. – scottt Apr 05 '14 at 03:13
  • thanks for your help. giving you an upvote, but going to wait to see if someone can offer an answer to the original question, i.e. how can we find out what process is causing low-memory and why is the strategy used in the question not working. – Harry Mexican Apr 06 '14 at 20:16
  • this actually doesn't answer why the values are not equal or whats wrong with existing code. – minhaz Apr 10 '14 at 20:07