Android的内存分配分配、内存、Android

2023-09-12 00:47:51 作者:前任只认钱

我收到一个位图大小超过虚拟经济的错误。我已阅读,有一个16MB的内存限制。 In这个线程罗曼盖伊说,你只能分配16 MB 内存为你的整个应用程序。

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 memory for your entire application".

不过,我的应用程序必须长时间运行内存才达到了极限。所以我的问题是:我怎么分配内存以我的应用程序...我怎么能得到分配给我的应用程序增加了(在最大16MB)?

However, my app must be running out of memory long before it reaches that limit. So my question is: how do I allocate memory to my application ... how can I get the allocation to my app increased (within the 16MB maximum)?

推荐答案

对于任何Java虚拟机,堆内存会自动增长到最大尺寸。但是,位图的虚拟机之外分配的,所以你不看他们很容易在统计数据。你能做的最好的事情就是确保您不使用大位图,或使用他们缩小 http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html

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

在Eclipse中,您可以生成一个堆转储当你在Android 1.6了,你可以分析与Eclipse MAT转储。

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.

应该有倾销堆中的1.6的文章在developer.android.com,但我无法找到它。 :(

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

安卓largeHeap =真正的

android:largeHeap="true"

在清单中。但是,这是非常病态谏,因为大多数应用程序并不需要这个。

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