I would like to increase the android virtual device map heap size with Eclipse. I tried to set the Max VM application heap size to 128 in the Eclipse AVD Manager, but it does not work, the line Runtime.getRuntime().maxMemory()/(1024*1024);
always returns 48, no matter the set heap size. Device ram size is set to 512. Selected target is Android 4.1.2 (API Level 16). Moreover, I have set android:largeHeap="true"
in the manifest file.
Is there a limit to max heap size (is 128MiB to much ?), or is there another file to edit or parameter to set ?
add large heap in Manifest file
<application
android:icon="@drawable/example"
android:label="@string/app_name"
android:largeHeap="true">
......
......
</application>
To do that, in Eclipse, go to "Debug Configurations". You can find that in the drop-down under the "debug" icon. Select "target", and select a preferred emulator target to launch. Then under "additional emulator command line options," add this:
-partition-size 128
Then CLOSE the emulator (and remove any devices), and click the debug icon, which will launch the preferred emulator you selected. This is important: Eclipse needs to launch the debugger, not AVD.
Note that the size (128) is in megabytes.
Take a look also here: http://viralpatel.net/blogs/jvm-java-increase-heap-size-setting-heap-size-jvm-heap/
Or: increase the AVD RAM and the max VM application heap size in VM options:
Go to Window-->AVD Manager-->Virtual Devices-->Edit.
Use the following code. I think it would be help you:
VMRuntime.getRuntime().setMinimumHeapSize(4 * 1024 * 1024);
you can't increase the heap size dynamically.
you can request to use more by using android:largeHeap="true" in the manifest, but you might not get any more heap size than normal, since it's only a request.
also, you can use native memory, so you actually bypass the heap size limitation.
here are some posts i've made about it:
How to cache bitmaps into native memory
JNI bitmap operations , for helping to avoid OOM when using large images
and here's a library i've made for it:
- https://github.com/AndroidDeveloperLB/AndroidJniBitmapOperations