簡體   English   中英

如何在android上檢查我的app堆內存大小?

[英]How to check my app heap memory size on android?

我想要我的app堆內存大小檢查。

拳頭我用android:largeHeap="true"

如何在Android上使用我的app堆內存大小檢查?

內存量取決於Android版本和設備型號。

public static void logHeap() {
        Double allocated = new Double(Debug.getNativeHeapAllocatedSize())/new Double((1024*1024));
        Double available = new Double(Debug.getNativeHeapSize())/(1024*1024.0);
        Double free = new Double(Debug.getNativeHeapFreeSize())/(1024*1024.0);
        DecimalFormat df = new DecimalFormat();
        df.setMaximumFractionDigits(2);
        df.setMinimumFractionDigits(2);

        Log.d("tag", "debug. ===Heap====Heap======Heap====Heap====Heap=====");
        Log.d("tag", "debug.heap native: allocated " + df.format(allocated) + "MB of " + df.format(available) + "MB (" + df.format(free) + "MB free)");
        Log.d("tag", "debug.memory: allocated: " + df.format(new Double(Runtime.getRuntime().totalMemory()/(1024*1024.0))) + "MB of " + df.format(new Double(Runtime.getRuntime().maxMemory()/(1024*1024.0)))+ "MB (" + df.format(new Double(Runtime.getRuntime().freeMemory()/(1024*1024.0))) +"MB free)");
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM