java如何在安卓上检查我的应用程序堆内存大小? 1 年,8 月 Questions & Answers 619 我要检查我的应用程序堆内存大小 首先我使用安卓:largeHeap="true" 如何在安卓上检查我的应用程序堆内存大小
# 1 楼答案 内存量取决于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)"); }
# 1 楼答案
内存量取决于Android版本和设备型号