Android的 - 成长堆(破片为例) - 字节分配..不加载任何位图破片、位图、为例、字节

2023-09-05 09:06:26 作者:今天xx很爱你

这发生在距离Splash屏幕主页的应用程序加载。它发生只在设备不上模拟器:

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图片...

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

我使用的设备是谷歌Nexus Prime的Andr​​oid 4.0的

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

有没有人遇到过同样的?任何人抛出一些专业知识......

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

推荐答案

您可能正在试图去codeA很大位图这会导致一个内存不足例外。这意味着,你正在努力实现的超过VM预算允许的设备上每个应用程序的操作,在堆内存消耗方面(这似乎是24 MB您的设备上,可能更对你的模拟器这就是为什么它不'T发生在那里!)。

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!).

试着品尝你的位图由两个例如一个系数:

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);