4

The software team in our graduation project asked for increasing the heap size per process in Android. They said that the default is "16MB" which isn't sufficient for them. How could I custom the size?

I found a commented line in the file: /acme/my_board/BoardConfig.mk in my android source code:

# USE_CUSTOM_RUNTIME_HEAP_MAX := "64M"

Is that what I need to edit??

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Osama Gamal
  • 1,161
  • 4
  • 12
  • 18
  • Is this for the default heap for any application, so you want to change it with custom build of the OS or is the goal to change the heap size at runtime of a particular application? – Quintin Robinson Jul 23 '10 at 23:15
  • Well, any of them will solve my problem. However, the second option "for specific" is much better. – Osama Gamal Jul 23 '10 at 23:59
  • This question kinda relates with a question I asked before on this issue, which you can check over here: http://stackoverflow.com/questions/3078301/dalvik-memory-allocation-how-to-change-the-default-limits According to the answers, you have to change the OS build, and the instructions posted in the answers should do the thing, even though I did not get to try them myself, for I was seeking a solution application-specific. – Luis Miguel Serrano Jul 24 '10 at 00:27

2 Answers2

3

In your onCreate method in your activity, or, if you want it for all your applications in a package, a custom Application object's onCreate, add

dalvik.system.VMRuntime.getRuntime().setMinimumHeapSize(yournumberhere);

Edit: Also note that Android will automatically increase the heap size if it needs more. So even though the default might be 16, if it needs more, it will increase it. However that might make a little hickup in a real-time situation which is bad. Therefore if you know it will go over 16 it's good to do it before-hand.

Moncader
  • 3,388
  • 3
  • 22
  • 28
  • 2
    It's also worthwhile to note that this isn't a sustainable method for increasing an application heap size, refer to http://developer.android.com/reference/dalvik/system/VMRuntime.html ... This class is deprecated. this is an internal Dalvik class that is not appropriate for general use. It will be removed from the public API in a future release. – Quintin Robinson Jul 24 '10 at 16:10
1

I got that answer through android-platform mailing list

You can change platform/dalvik/vm/Init.c

For example to make it 32MB, you can do below

gDvm.heapSizeMax = 32 * 1024 * 1024;

Another suggested approach is to update your system.prop

Regards, Muthu Subramaniam

Osama Gamal
  • 1,161
  • 4
  • 12
  • 18