0

I have an application that is communicating with an arduino and it runs a netty instance for controlling the arduino. The problem is I am not running out of memory but total heap size to used heap size is too low according to the adb logcat I am always around %10 free so any request to the netty server triggers a gc at which time I get a bunch of,

D/dalvikvm( 2862): WAIT_FOR_CONCURRENT_GC blocked 189ms

even simple requests that does not do anything (at least by me) loses atleast a second on gc pauses. I have

android:largeHeap="true"

set in my manifest and the simulator device has VM Heap of 512 mb but it is not allocating anywhere near that number (It is allocating around 10MB). I do not have a memory leak because 10% free is stable it goes +/- 2-3%. Even on a phone with 2 gigs of ram (with all other applications closed) I am always running with less then 2 3 MB of free heap is there a workaround for this?

1 Answers1

1

The size of the device RAM doesn't really matter, as having a 2 GB RAM doesn't mean you'll get a 2GB heap.

The minimum heap size specified by Google in their recommendations is 16MB. You will not get a smaller heap than that.

largeHeap only works on Android 3.0 and above, and it doesn't guarantee a bigger heap size.

There isn't much you can do to get a bigger heap, but you can rewrite your app using the NDK, in which heap size doesn't matter because you run outside the dalvik VM, and can hence use (almost) all of the device's RAM if need be.

However, running with 10% free of heap space isn't bad.

Raghav Sood
  • 79,170
  • 20
  • 177
  • 186
  • 1
    large heap works I get 256 MB max on the phone but it does not let me use it (10-11 allocated) I am constantly waiting for gc. – Suleymanoglu Naim Mar 27 '13 at 01:44
  • Less than 16MB is non-standard and you really do not have to support it, but it can happen in unusual cases (e.g., on CyanogenMod Android releases which allow the user to configure the heap size directly down to I think 12MB). This is a user action and IMO it is the user's problem if an app cannot run in 12MB, but some users may not see it that way, and users write ratings! :-) – Carl May 29 '13 at 13:29
  • My Nexus 4: 03-30 11:14:12.954: D/dalvikvm(1572): GC_CONCURRENT freed 314K, 6% free 9851K/10424K, paused 3ms+6ms, total 33ms So the initial heap size is only 10M (10424K).... I don't know why this will happen. getMemoryClass() returns 192 – HackNone Mar 30 '15 at 07:08