0

ビットマップを使用して画像が保存される顔検出アプリを作成しています。コードにそのようなエラーはありませんが、デバイスで実行すると例外が表示されます。以下は Logcat の詳細です。前もって感謝します

 11-06 15:50:49.340: D/dalvikvm(32555): GC_FOR_ALLOC freed 43K, 8% free 12131K/13059K, paused 21ms, total 25ms
    11-06 15:50:49.390: I/dalvikvm-heap(32555): Grow heap (frag case) to 22.111MB for 10036240-byte allocation
    11-06 15:50:49.425: D/dalvikvm(32555): GC_CONCURRENT freed <1K, 5% free 21931K/22919K, paused 14ms+2ms, total 35ms
    11-06 15:50:49.730: D/dalvikvm(32555): GC_FOR_ALLOC freed 0K, 5% free 21932K/22919K, paused 10ms, total 10ms
    11-06 15:50:49.920: I/dalvikvm-heap(32555): Grow heap (frag case) to 60.396MB for 40144912-byte allocation
    11-06 15:50:49.940: D/dalvikvm(32555): GC_CONCURRENT freed 0K, 2% free 61136K/62151K, paused 1ms+2ms, total 20ms
    11-06 15:50:50.310: D/dalvikvm(32555): GC_FOR_ALLOC freed 9802K, 18% free 51335K/62151K, paused 15ms, total 15ms
    11-06 15:50:50.310: I/dalvikvm-heap(32555): Forcing collection of SoftReferences for 20072464-byte allocation
    11-06 15:50:50.325: D/dalvikvm(32555): GC_BEFORE_OOM freed 9K, 18% free 51326K/62151K, paused 17ms, total 17ms
    11-06 15:50:50.325: E/dalvikvm-heap(32555): Out of memory on a 20072464-byte allocation.
    11-06 15:50:50.325: I/dalvikvm(32555): "main" prio=5 tid=1 RUNNABLE
    11-06 15:50:50.325: I/dalvikvm(32555):   | group="main" sCount=0 dsCount=0 obj=0x41982508 self=0x419728e8
    11-06 15:50:50.325: I/dalvikvm(32555):   | sysTid=32555 nice=0 sched=0/0 cgrp=apps handle=1074306864
    11-06 15:50:50.330: I/dalvikvm(32555):   | schedstat=( 683836904 179752181 2016 ) utm=39 stm=29 core=3
    11-06 15:50:50.335: I/dalvikvm(32555):   at android.media.FaceDetector.<init>(FaceDetector.java:~121)
    11-06 15:50:50.335: I/dalvikvm(32555):   at com.example.facedetection.FaceDetection$MyView.<init>(FaceDetection.java:56)
    11-06 15:50:50.335: I/dalvikvm(32555):   at com.example.facedetection.FaceDetection.onCreate(FaceDetection.java:23)
    11-06 15:50:50.355: I/dalvikvm(32555):   at android.app.Activity.performCreate(Activity.java:5206)
    11-06 15:50:50.355: I/dalvikvm(32555):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
    11-06 15:50:50.360: I/dalvikvm(32555):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
    11-06 15:50:50.360: I/dalvikvm(32555):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
    11-06 15:50:50.360: I/dalvikvm(32555):   at android.app.ActivityThread.access$600(ActivityThread.java:140)
    11-06 15:50:50.360: I/dalvikvm(32555):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
    11-06 15:50:50.360: I/dalvikvm(32555):   at android.os.Handler.dispatchMessage(Handler.java:99)
    11-06 15:50:50.365: I/dalvikvm(32555):   at android.os.Looper.loop(Looper.java:137)
    11-06 15:50:50.365: I/dalvikvm(32555):   at android.app.ActivityThread.main(ActivityThread.java:4898)
    11-06 15:50:50.365: I/dalvikvm(32555):   at java.lang.reflect.Method.invokeNative(Native Method)
    11-06 15:50:50.370: I/dalvikvm(32555):   at java.lang.reflect.Method.invoke(Method.java:511)
    11-06 15:50:50.370: I/dalvikvm(32555):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
    11-06 15:50:50.370: I/dalvikvm(32555):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
    11-06 15:50:50.370: I/dalvikvm(32555):   at dalvik.system.NativeStart.main(Native Method)
    11-06 15:50:50.370: D/AndroidRuntime(32555): Shutting down VM
    11-06 15:50:50.370: W/dalvikvm(32555): threadid=1: thread exiting with uncaught exception (group=0x419812a0)
    11-06 15:50:50.390: E/AndroidRuntime(32555): FATAL EXCEPTION: main
    11-06 15:50:50.390: E/AndroidRuntime(32555): java.lang.OutOfMemoryError
    11-06 15:50:50.390: E/AndroidRuntime(32555):    at android.media.FaceDetector.<init>(FaceDetector.java:121)
    11-06 15:50:50.390: E/AndroidRuntime(32555):    at com.example.facedetection.FaceDetection$MyView.<init>(FaceDetection.java:56)
    11-06 15:50:50.390: E/AndroidRuntime(32555):    at com.example.facedetection.FaceDetection.onCreate(FaceDetection.java:23)
    11-06 15:50:50.390: E/AndroidRuntime(32555):    at android.app.Activity.performCreate(Activity.java:5206)
    11-06 15:50:50.390: E/AndroidRuntime(32555):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
    11-06 15:50:50.390: E/AndroidRuntime(32555):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
    11-06 15:50:50.390: E/AndroidRuntime(32555):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
    11-06 15:50:50.390: E/AndroidRuntime(32555):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
    11-06 15:50:50.390: E/AndroidRuntime(32555):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
    11-06 15:50:50.390: E/AndroidRuntime(32555):    at android.os.Handler.dispatchMessage(Handler.java:99)
    11-06 15:50:50.390: E/AndroidRuntime(32555):    at android.os.Looper.loop(Looper.java:137)
    11-06 15:50:50.390: E/AndroidRuntime(32555):    at android.app.ActivityThread.main(ActivityThread.java:4898)
    11-06 15:50:50.390: E/AndroidRuntime(32555):    at java.lang.reflect.Method.invokeNative(Native Method)
    11-06 15:50:50.390: E/AndroidRuntime(32555):    at java.lang.reflect.Method.invoke(Method.java:511)
    11-06 15:50:50.390: E/AndroidRuntime(32555):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
    11-06 15:50:50.390: E/AndroidRuntime(32555):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
    11-06 15:50:50.390: E/AndroidRuntime(32555):    at dalvik.system.NativeStart.main(Native Method)
4

3 に答える 3

0

次のように使用した後は、ビットマップをリサイクルしてください。

@Override
    public void onDestroy()
    {   
        cleanUp();
        super.onDestroy();
    }

    private void cleanUp()
    {   
        if(bmp!=null){
            bmp.recycle();
            bmp=null;
        }
        if(realBmp!=null){
            realBmp.recycle();
            realBmp=null;
        }      
        System.gc();
        Runtime.getRuntime().gc();  
    }
于 2013-11-06T10:38:26.493 に答える
0

もう使用しないビットマップをリサイクルする必要があります。また、これを読んでビットマップを効率的にロードすることもできます: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

于 2013-11-06T20:37:31.373 に答える
0

Bitmap が正常に動作したら、その時点で bitmap をリサイクルして null に割り当てます。

Bitmap bitmap;

Bitmap での作業が完了したら。

bitmap.recycle();
bitmap=null;
于 2013-11-06T10:52:37.557 に答える