0

从 Eclipse 的 DDMS 角度来看,我有以下内存详细信息。

在此处输入图像描述

但是,尽管实现了以下代码,但我无法获得上图中显示的值。

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");
    } 

我得到以下值:

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

是否有任何其他 API 可以获取详细信息?

4

0 回答 0