0

I have the following memory details from the DDMS perspective of Eclipse.

enter image description here

However in spite of implementing the following code, I'm unable to obtain the values shown in the above image.

private void logHeap() {

        long maxMemory = Runtime.getRuntime().maxMemory()/ (1024*1024);
        long totalMemory = Runtime.getRuntime().totalMemory() / (1024*1024);

        long heapSize = Debug.getNativeHeapSize()/(1024*1024);
        long allocatedHeapSize = Debug.getNativeHeapAllocatedSize() / (1024*1024);
        long freeHeapSize = Debug.getNativeHeapFreeSize() / (1024*1024);


        DecimalFormat df = new DecimalFormat();
        df.setMaximumFractionDigits(2);
        df.setMinimumFractionDigits(2);

        Log.d(TAG, "debug. =================================");
        Log.d(TAG,"Max memory: "+df.format(maxMemory)+" MB");
        Log.d(TAG,"Total memory: "+df.format(totalMemory)+" MB");

        Log.d(TAG,"Heap Size: "+df.format(heapSize)+" MB");
        Log.d(TAG,"Allocated Heapsize: "+df.format(allocatedHeapSize)+" MB");
        Log.d(TAG,"Free Heapsize: "+df.format(freeHeapSize)+" MB");
    } 

I'm getting the following values:

Max Memory : 36.00MB
Total Memory : 7.00 MB
Heap Size : 3.00 MB
allocated heapsize : 3.00 MB
free heapsize : 0.00 MB

Are there any other APIs to obtain the details?

Santosh V M
  • 1,541
  • 7
  • 25
  • 41
  • 1
    http://stackoverflow.com/questions/2298208/how-to-discover-memory-usage-of-my-application-in-android/2299813#2299813 – CommonsWare May 28 '13 at 23:09
  • 1
    Also, the native heap is not the same as the managed heap. You're comparing apples to oranges. – fadden May 29 '13 at 00:12

0 Answers0