How to increase android virtual device max heap size?

血红的双手。 提交于 2020-01-03 08:41:12

问题


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 ?


回答1:


add large heap in Manifest file

<application

        android:icon="@drawable/example"
        android:label="@string/app_name" 
        android:largeHeap="true">

      ......
      ......

</application>



回答2:


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.




回答3:


Use the following code. I think it would be help you:

VMRuntime.getRuntime().setMinimumHeapSize(4 * 1024 * 1024);



回答4:


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


来源:https://stackoverflow.com/questions/14232440/how-to-increase-android-virtual-device-max-heap-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!