我想要检查我的应用堆内存大小。
拳头我使用android:largeHeap="true"
如何在 android 上检查我的应用堆内存大小?
最佳答案
内存量取决于 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)");
}
关于java - 如何在 Android 上检查我的应用程序堆内存大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45455286/