Android - 增长堆(碎片案例) - 字节分配.. 不加载任何位图 [英] Android - Grow Heap (Frag Case) - Byte Allocation.. Not Loading any bitmaps

查看:17
本文介绍了Android - 增长堆(碎片案例) - 字节分配.. 不加载任何位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应用从启动画面加载到主页时会发生这种情况.它只发生在设备上而不是模拟器上:

This happens when the app loads from Splash screen to Main page. It happens only on the device not on simulator:

05-17 08:10:16.627: I/dalvikvm-heap(14021): Grow heap (frag case) to 20.580MB for     2424256-byte allocation
05-17 08:10:16.666: D/dalvikvm(14021): GC_FOR_ALLOC freed 1K, 3% free 21000K/21511K, paused 21ms
05-17 08:10:16.697: D/dalvikvm(14021): GC_CONCURRENT freed 116K, 3% free 20885K/21511K, paused 2ms+2ms
05-17 08:10:16.720: D/dalvikvm(14021): GC_FOR_ALLOC freed 44K, 4% free 20841K/21511K, paused 10ms
05-17 08:10:16.728: I/dalvikvm-heap(14021): Grow heap (frag case) to 24.533MB for 4310896-byte allocation

我使用了 Ecplise MAT - 字节分配已解决 - Android.Graphics.Bitmap $preloaded images...

I used Ecplise MAT - the byte allocation resolved - Android.Graphics.Bitmap $preloaded images...

我使用的设备是 Google Nexus Prime,Android 4.0

The device I am using is Google Nexus Prime, Android 4.0

有人遇到过吗?有人可以抛出一些专业知识....

Has anyone encountered the same? Can someone throw some expertise....

推荐答案

您可能正在尝试解码一个非常大的 Bitmap,这会导致 OutOfMemory 异常.这意味着您尝试实现的操作超出了设备上每个应用程序允许的 VM 预算,就堆内存消耗而言(在您的设备上似乎是 24 MB,在您的模拟器上可能更多,这就是为什么它没有不会发生在那里!)

You are probably trying to decode a very big Bitmap which results in an OutOfMemory exception. It means that the operation you are trying to achieve is exceeding the VM Budget allowed for each application on your device, in terms of heap memory consumption (which appears to be 24 MB on your device, probably more on your emulator which is why it doesn't happen there!).

例如尝试以两倍的因子对您的 Bitmap 进行采样:

Try to sample your Bitmapby a factor of two for instance:

BitmapFactory.Options o = new BitmapFactory.Options();
o.inSampleSize = 2;
Bitmap b = BitmapFactory.decodeFile(pathToBitmap, o);

这篇关于Android - 增长堆(碎片案例) - 字节分配.. 不加载任何位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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