ゲームを作っています。それは完璧に機能しますが、時々次のようなメッセージをスローします: Out of memory on a 1024016-byte allocation
! Androidが実際に1MBのメモリを割り当てられない理由がわかりませんか? 関数を使用してBitmapFactory.decodeResource(res, id)
います。ビットマップが使い物にならなくなったら、すぐにリサイクルします。ビットマップのサイズも縮小しました!誰かがこの問題を解決する方法を知っていれば、私は感謝します! 以下の LogCat:
10-11 09:56:28.312 I/dalvikvm(13613): "main" prio=5 tid=1 RUNNABLE
10-11 09:56:28.312 I/dalvikvm(13613): | group="main" sCount=0 dsCount=0 obj=0x40a32460 self=0x18e5828
10-11 09:56:28.312 I/dalvikvm(13613): | sysTid=13613 nice=0 sched=0/0 cgrp=default handle=1075090664
10-11 09:56:28.312 I/dalvikvm(13613): | schedstat=( 0 0 0 ) utm=788 stm=85 core=0
10-11 09:56:28.320 I/dalvikvm(13613): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
10-11 09:56:28.320 I/dalvikvm(13613): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
10-11 09:56:28.320 I/dalvikvm(13613): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
10-11 09:56:28.320 I/dalvikvm(13613): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:374)
10-11 09:56:28.320 I/dalvikvm(13613): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:404)
10-11 09:56:28.320 I/dalvikvm(13613): at mygames.airdefense.extensions.FunctionalHelper.getBmpFromRes(FunctionalHelper.java:30)
10-11 09:56:28.320 I/dalvikvm(13613): at mygames.airdefense.weathereffect.Wind.<init>(Wind.java:37)
10-11 09:56:28.320 I/dalvikvm(13613): at mygames.airdefense.game.GameEngineMultiPlayer.InitObjects(GameEngineMultiPlayer.java:268)
10-11 09:56:28.320 I/dalvikvm(13613): at mygames.airdefense.game.GameEngineMultiPlayer.<init>(GameEngineMultiPlayer.java:170)
10-11 09:56:28.320 I/dalvikvm(13613): at mygames.airdefense.game.GameActivity.onCreate(GameActivity.java:189)
10-11 09:56:28.320 I/dalvikvm(13613): at android.app.Activity.performCreate(Activity.java:4465)
10-11 09:56:28.320 I/dalvikvm(13613): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-11 09:56:28.320 I/dalvikvm(13613): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
10-11 09:56:28.320 I/dalvikvm(13613): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
10-11 09:56:28.320 I/dalvikvm(13613): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3351)
10-11 09:56:28.320 I/dalvikvm(13613): at android.app.ActivityThread.access$700(ActivityThread.java:123)
10-11 09:56:28.320 I/dalvikvm(13613): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151)
10-11 09:56:28.320 I/dalvikvm(13613): at android.os.Handler.dispatchMessage(Handler.java:99)
10-11 09:56:28.320 I/dalvikvm(13613): at android.os.Looper.loop(Looper.java:137)
10-11 09:56:28.320 I/dalvikvm(13613): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-11 09:56:28.320 I/dalvikvm(13613): at java.lang.reflect.Method.invokeNative(Native Method)
10-11 09:56:28.320 I/dalvikvm(13613): at java.lang.reflect.Method.invoke(Method.java:511)
10-11 09:56:28.320 I/dalvikvm(13613): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-11 09:56:28.320 I/dalvikvm(13613): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-11 09:56:28.320 I/dalvikvm(13613): at dalvik.system.NativeStart.main(Native Method)
10-11 09:56:28.320 I/dalvikvm(13613):
10-11 09:56:28.328 D/skia (13613): --- decoder->decode returned false
10-11 09:56:28.335 D/AndroidRuntime(13613): Shutting down VM
10-11 09:56:28.335 W/dalvikvm(13613): threadid=1: thread exiting with uncaught exception (group=0x40a311f8)
10-11 09:56:28.351 E/AndroidRuntime(13613): FATAL EXCEPTION: main
10-11 09:56:28.351 E/AndroidRuntime(13613): java.lang.OutOfMemoryError
10-11 09:56:28.351 E/AndroidRuntime(13613): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
10-11 09:56:28.351 E/AndroidRuntime(13613): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
10-11 09:56:28.351 E/AndroidRuntime(13613): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
10-11 09:56:28.351 E/AndroidRuntime(13613): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:374)
10-11 09:56:28.351 E/AndroidRuntime(13613): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:404)
10-11 09:56:28.351 E/AndroidRuntime(13613): at mygames.airdefense.extensions.FunctionalHelper.getBmpFromRes(FunctionalHelper.java:30)
10-11 09:56:28.351 E/AndroidRuntime(13613): at mygames.airdefense.weathereffect.Wind.<init>(Wind.java:37)
10-11 09:56:28.351 E/AndroidRuntime(13613): at mygames.airdefense.game.GameEngineMultiPlayer.InitObjects(GameEngineMultiPlayer.java:268)
10-11 09:56:28.351 E/AndroidRuntime(13613): at mygames.airdefense.game.GameEngineMultiPlayer.<init>(GameEngineMultiPlayer.java:170)
10-11 09:56:28.351 E/AndroidRuntime(13613): at mygames.airdefense.game.GameActivity.onCreate(GameActivity.java:189)
10-11 09:56:28.351 E/AndroidRuntime(13613): at android.app.Activity.performCreate(Activity.java:4465)
10-11 09:56:28.351 E/AndroidRuntime(13613): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-11 09:56:28.351 E/AndroidRuntime(13613): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
10-11 09:56:28.351 E/AndroidRuntime(13613): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
10-11 09:56:28.351 E/AndroidRuntime(13613): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3351)
10-11 09:56:28.351 E/AndroidRuntime(13613): at android.app.ActivityThread.access$700(ActivityThread.java:123)
10-11 09:56:28.351 E/AndroidRuntime(13613): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151)
10-11 09:56:28.351 E/AndroidRuntime(13613): at android.os.Handler.dispatchMessage(Handler.java:99)
10-11 09:56:28.351 E/AndroidRuntime(13613): at android.os.Looper.loop(Looper.java:137)
10-11 09:56:28.351 E/AndroidRuntime(13613): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-11 09:56:28.351 E/AndroidRuntime(13613): at java.lang.reflect.Method.invokeNative(Native Method)
10-11 09:56:28.351 E/AndroidRuntime(13613): at java.lang.reflect.Method.invoke(Method.java:511)
10-11 09:56:28.351 E/AndroidRuntime(13613): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-11 09:56:28.351 E/AndroidRuntime(13613): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-11 09:56:28.351 E/AndroidRuntime(13613): at dalvik.system.NativeStart.main(Native Method)
10-11 09:56:28.367 W/ActivityManager( 185): Force finishing activity mygames.airdefense/.game.GameActivity