为什么 ASUS Transformer Prime 是唯一出现内存不足异常的设备
我正在开发一个需要显示 4 个大位图(6 x 屏幕尺寸)的 Android 应用程序。一开始,我对此有疑问,但对适用于整个设备的内存管理进行代码优化。但在 4.0.3 android 版本的 ASUS Transformer Prime 上,出现 OutOfMemory 错误。这很奇怪,因为堆大小似乎为 256Mb。与其他可以正确运行的设备相比,有很多优势。
我们已激活大堆并停用硬件加速。
你知道我们的问题吗?
I'm working on an Android application that needs to display 4 big bitmaps (6 x screen size). At the beginning, I've problem with that but with code optimization on memory management that works on whole devices. But on ASUS Transformer Prime in 4.0.3 android version, I've a OutOfMemory error. It's very strange because the Heap Size seems to be to 256Mb. A lot compare to other devices on which it runs correctly.
We have activated Large Heap and deactivated Hardware accelerated.
Have you an idea of our problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的屏幕为 1280x800,因此屏幕大小的 32bpp 位图将需要不到 4MB,而 6 x 屏幕大小的位图将需要 23.5MB。您想要其中四个...即 93.75MB。
进程堆限制因设备而异,但我认为 64MB 已经很多了(也许我落后了时代)。 256MB 太大了!
恕我直言,您根本不应该尝试将如此大的位图保留在内存中。您最好将它们分成不大于屏幕的图块,并根据需要加载图块。
或者,尝试使用 16bpp 图像或在 JNI 中(即在 C 中)为大量位图分配空间,并完全绕过 Java 堆管理。
Your screen is 1280x800, therefore a screen-sized 32bpp bitmap will require just under 4MB, and a 6 x screen size bitmap will need 23.5MB. And you want four of those... that's 93.75MB.
The process heap limit varies from device to device but I'd consider 64MB to be a lot (perhaps I'm behind the times). 256MB is huge!
IMHO you shouldn't be trying to keep such massive bitmaps in memory at all. You'd be better off breaking them up into tiles that are no bigger than the screen and loading the tiles as they are needed.
Alternatively, try using 16bpp images or allocating the space for your massive bitmaps in JNI (i.e. in C) and bypass the Java heap management entirely.