android中内存不足异常的处理
在android中,我计算了堆内存并将其转储到文件中,现在知道如何清除数据,以便堆大小减小,应用程序正常运行android中内存不足异常的处理,android,out-of-memory,Android,Out Of Memory,在android中,我计算了堆内存并将其转储到文件中,现在知道如何清除数据,以便堆大小减小,应用程序正常运行 public static void logHeap() { Double allocated = new Double(Debug.getNativeHeapAllocatedSize())/new Double((1048576)); Double available = new Double(Debug.getNativeHeap
public static void logHeap() {
Double allocated = new Double(Debug.getNativeHeapAllocatedSize())/new Double((1048576));
Double available = new Double(Debug.getNativeHeapSize())/1048576.0;
Double free = new Double(Debug.getNativeHeapFreeSize())/1048576.0;
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
df.setMinimumFractionDigits(2);
Log.d("tag", "debug. =================================");
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()/1048576)) + "MB of " + df.format(new Double(Runtime.getRuntime().maxMemory()/1048576))+ "MB (" + df.format(new Double(Runtime.getRuntime().freeMemory()/1048576)) +"MB free)");
}
垃圾收集器的任务是释放内存,但它不会自动清除。我的应用程序运行得很慢。您需要编写代码,这样您就不会遇到内存泄漏。在进程结束后显示为15mb。同样,当我导航到下一个屏幕时,您的活动将暂停而不是销毁。所以它会占用一些空间。你有内存不足的异常吗?