安卓内存分配 [英] Android memory allocation

查看:35
本文介绍了安卓内存分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到位图大小超出 VM 预算"错误.我已经读到有 16MB 的内存限制.这个帖子 Romain Guy 说你只能分配 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 VM 一样,堆内存会自动增长到最大大小.但是,位图是在 VM 外部分配的,因此您不会在统计信息中轻松看到"它们.你能做的最好的事情是确保你不使用大的位图,或者使用
缩小它们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

当您使用 Android 1.6 或更高版本时,您可以从 Eclipse 生成堆转储,并且您可以使用 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.

developer.android.com 上应该有一篇关于在 1.6 上转储堆的文章,但我找不到.:(

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"

android:largeHeap="true"

在清单中.但这是非常不明智的,因为大多数应用程序不需要这个.

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

这篇关于安卓内存分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆