What Debug.getNativeHeapFreeSize Really Mean

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; //1MB long threshold = mi.threshold / 1048576L; //1MB String descr = String .format(Locale.US, "+++System available MB:%d\nIs low:%b\nThreshold:%d\nMem class:%d\nallocated:%f\nfree:%f\navailable:%f\n", availableMegs, mi.lowMemory, threshold, activityManager.getMemoryClass(), allocated, free, available); Ll(descr); } catch (Exception e) { Ll(e); } } 

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.

+6
source share

Source: https://habr.com/ru/post/955831/


All Articles