繁体   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