I use the following code to use memory in my application:
public static void dumpMemoryUsage(Context ctx) { try { MemoryInfo mi = new MemoryInfo(); double allocated = new Double(Debug.getNativeHeapAllocatedSize()); double available = new Double(Debug.getNativeHeapSize()); double free = new Double(Debug.getNativeHeapFreeSize()); ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE); activityManager.getMemoryInfo(mi); long availableMegs = mi.availMem / 1048576L;
And I run it on two different devices Nexus (2011 model) and Galaxy Note 1. Galaxy Note has memory problems and very often with memory errors as soon as I add 1-2 bitmaps.
Here is the dump:
Nexus:
+++System available MB:154 Is low:false Threshold:94 Mem class:96 allocated:5663544.000000 free:1377480.000000 available:7081984.000000
Galaxy Note:
+++System available MB:316 Is low:false Threshold:64 Mem class:64 allocated:5361664.000000 free:155648.000000 available:5832704.000000
Note that calling Debug.getNativeHeapFreeSize () returns 1377480.000000 on the bunch and ONLY 155648.000000 in the galaxy. How is this possible. What does it mean? I did both tests in a new installation of the application without the work being done by the application - just by presenting the first screen, on which there are almost no several text elements and buttons. The Galaxy Note 1 has a memory class of 64 MB, so I donโt think I push this limit. I have no memory problems on the Nexus, even when I add a lot of bitmaps on the screen, so I donโt think I use too much memory.
source share