我已经在我的布局上加载了 3ListView
秒和 1 秒。EditText
当我触摸 时EditText
,键盘打开。在那一刻,我使用以下代码检查内存大小:
Runtime rt = Runtime.getRuntime();
long vmAlloc = rt.totalMemory() - rt.freeMemory();
long nativeAlloc = Debug.getNativeHeapAllocatedSize();
Log.d("Memory",className+"Maximum : "+formatMemoeryText(rt.maxMemory()));
Log.d("Memory",className+"VM Heap : "+formatMemoeryText(rt.totalMemory()));
Log.d("Memory",className+"NativHeap : "+formatMemoeryText(Debug.getNativeHeapSize()));
Log.d("Memory",className+"VM (A) : "+formatMemoeryText(vmAlloc));
Log.d("Memory",className+"Nati(A) : "+formatMemoeryText(nativeAlloc));
Log.d("Memory",className+"TotalAll : "+formatMemoeryText(nativeAlloc+vmAlloc));
Log.d("Memory", "----------------------------------------------------");
每次键盘打开本机堆大小都会增加。最终应用程序将强制关闭。
我试过了:
System.gc();
Runtime.getRuntime().gc();
但它只减少了大约 0.5-1MB。下次我打开键盘时,它会增加 20-30MB。
如何防止应用关闭或清除其本机堆内存?