Android memory allocation

后端 未结 4 1094
难免孤独
难免孤独 2020-11-27 03:34

I am getting a \"bitmap size exceeds VM budget\" error. I have read that there is a 16MB memory limit. In this thread Romain Guy says that \"you can only allocate 16 MB of

相关标签:
4条回答
  • 2020-11-27 04:04

    If you're using threads, then the debugger might be the source of the problem. If you run the app under the debugger, then any threads created will still be retained by the debugger, even when they're finished running. This leads to memory errors that won't occur when the app is running without the debugger.

    http://code.google.com/p/android/issues/detail?id=7979

    https://android.googlesource.com/platform/dalvik/+/master/docs/debugger.html

    0 讨论(0)
  • 2020-11-27 04:08

    I found the answer for your question recently.

    Go to Android SDK Directory and
    run sdk manager (Tools->android run this file)

    In SDK manager go to Tools-->Manage AVDs

    Now Android Virtual Device Manager Dialogue box is open..

    in that window select your AVD and click Edit

    Now in SD card section select SIZE and set 1024 MiB in Hardware section click New and select property " Maximum VM application heap Size" Now set 100 (based on your app requirement) Finally click "Edit AVD"

    After edit click refresh button on sdk Manager

    Now run your app in AVD your problem is solved.

    0 讨论(0)
  • 2020-11-27 04:27

    Note that the heap limit is device-dependent. On a Droid or Nexus One, that limit is 24 MB (to accommodate the larger graphic resources.)

    0 讨论(0)
  • 2020-11-27 04:28

    As with any Java VM, the heap memory will automatically grow to the max size. But, bitmaps are allocated outside the VM, so you don't "see" them easily in the stats. The best thing you can do is make sure you don't use large bitmaps, or scale them down using
    http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html

    From Eclipse you can generate a heap dump when you are on Android 1.6 or up and you can analyze the dump with Eclipse MAT.

    Generally you can't control the max heap size on a real device, unless you are working with custom hardware or firmware.

    There should be an article at developer.android.com on dumping the heap on 1.6, but I'm unable to find it. :(

    Edit
    Also, I have to mention that you can request more memory for applications by using

    android:largeHeap="true"

    in the manifest. But this is highly ill-adviced as most applications do not need this.

    0 讨论(0)
提交回复
热议问题