Reputation: 609
I use the following code to get the memory usage.
double allocated = Debug.getNativeHeapAllocatedSize() / (double) 1048576;
double available = Debug.getNativeHeapSize() / (double) 1048576.0;
double free = new Double(Debug.getNativeHeapFreeSize()) / (double) 1048576.0;
And I get the following log:
07-15 12:59:11.149: DEBUG/NKHeap(9363): debug.heap native: allocated 13,220MB of 16,059MB (0,108MB free)
My problem is that the free plus the allocated don't add up to the total. Am I missing something basic, or the is the precision I should expect?
Upvotes: 1
Views: 545
Reputation: 5542
To get the memory usage try something like:
Debug.MemoryInfo memoryInfo = new Debug.MemoryInfo();
Debug.getMemoryInfo(memoryInfo);
String memMessage = String.format("Memory: Pss=%.2f MB,
Private=%.2f MB, Shared=%.2f MB",
memoryInfo.getTotalPss() / 1024.0,
memoryInfo.getTotalPrivateDirty() / 1024.0,
memoryInfo.getTotalSharedDirty() / 1024.0);
You can read more about it in this blog here.
Upvotes: 1