Search code examples
androidmemory-managementallocation

Allocate more than 512mb ram on android


I'm writing a litte android app which fills the ram of a device for testing purposes. But I'm not allowed to allocate more than 512MB. The error log says:

Throwing OutOfMemoryError "Failed to allocate a 1000012 byte allocation with 229520 free bytes and 224KB until OOM"

Alloc partial concurrent mark sweep GC freed 6(192B) AllocSpace objects, 0(0B) LOS objects, 0% free, 511MB/512MB 

Clamp target GC heap from 527MB to 512MB

I'm trying to allocate more ram after catching the oom exception - without success.

Is there a way to allocate more memory?


Solution

  • Not in Java. Each Android app has a heap limit. Normally, that's a lot lower than 512MB; I presume that you added android:largeHeap="true" to your manifest to get it that large.

    If you need to allocate more than that, you will need to drop down to using the NDK, as allocations made in native code do not count against the Dalvik/ART heap limit.