Native Heap Memory size increase when open the keyboard - android

android, java

Solution

It is not that your app is crashing due to keyboard causing out of memory, there must be some thing in your program which is causing memory leak yes when you request keyboard by focusing on input field or programatically it allocate memory but not so huge that cause your program to crash, please review your code, and find memory leaks.

Problem

I've loaded 3 `ListView`s and one `EditText` on my layout. When I touch the `EditText`, the keyboard opens. At that instant I check the memory size using this code: ``` 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", "----------------------------------------------------"); ``` Every time the keyboard opens the native heap size increases. Eventually the app will force close. I've tried: ``` System.gc(); Runtime.getRuntime().gc(); ``` But it only reduces it by about 0.5-1MB. The very next time I open the keyboard it increases by 20-30MB. How do I prevent the app from closing or clear its native heap memory?

Original source