Why am I getting WIN DEATH: Window{45087aa8 com.gigabites.fortune/com.gigabites.fortune.BuildActivity paused=false} error?

StackOverflow https://stackoverflow.com/questions/8819174

Pergunta

I've looked around and from other people's posts I think this error is because my activity may exceed heap limits. I am manipulating some bitmaps and have applied techiniques to reduce heap size of my apps such as not using Bitmap.createBitmap() and instead enlarging a tiny bitmap as a blank bitmap to modify. I am also using the inPurgable options on created bitmap. Here is my code.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i("INFO","At 2###########");
    setContentView(R.layout.landingscreen);
    Thread thread = new Thread(this);
    thread.start();

}

My activity implements Runnable and this is the run()

    public void run() {
    BitmapFactory.Options factoryOptions = new BitmapFactory.Options();
    factoryOptions.inPurgeable = true;
    factoryOptions.inInputShareable = true;
    Bitmap tempCBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.c6,factoryOptions);
    cBitmap = tempCBitmap.copy(Bitmap.Config.ARGB_8888, true);
    PrepareLines();
    Bitmap dBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dummy);
    Bitmap textLayer = Bitmap.createScaledBitmap(dBitmap, w, h, false);
    Bitmap workLayer = Bitmap.createScaledBitmap(dBitmap, w, h, false);
    canvas = new Canvas(textLayer);
    canvas.drawText(lineOne, xCenter, yCenter, paint);
    canvas.drawText(lineTwo, xCenter, yCenter+20, paint);
    canvas.drawText(lineThree, xCenter, yCenter+40, paint);

    Camera mCamera = new Camera();
    Matrix mMatrix = new Matrix();
    mCamera.save();
    mCamera.rotateY(yDegreeRotate+8);
    mCamera.getMatrix(mMatrix);
    mCamera.restore();

    mMatrix.preTranslate(-xCenter, (-yCenter)-verticalOffset);
    mMatrix.postTranslate(xCenter, yCenter+verticalOffset);
    Log.i("INFO","At before first draw ###########");


    canvas.setBitmap(workLayer);
    canvas.drawBitmap(Bitmap.createBitmap(textLayer,0,0,xCenter,h), mMatrix, paint);

    canvas.setBitmap(cBitmap);
    canvas.drawBitmap(workLayer, new Matrix(), paint);

    mMatrix = new Matrix();
    workLayer = Bitmap.createScaledBitmap(dBitmap, w, h, false);
    dBitmap = null;
    System.gc();

    mCamera.rotateY(-yDegreeRotate);
    mCamera.getMatrix(mMatrix);
    // WIN DEATH HERE
    mCamera.restore();
    // WIN DEATH HERE;
    mMatrix.preTranslate(0 , (-yCenter)-verticalOffset);
    mMatrix.postTranslate(xCenter, (yCenter)+verticalOffset);
    Log.i("INFO","At before second draw ###########");



    canvas.setBitmap(workLayer);
    canvas.drawBitmap(Bitmap.createBitmap(textLayer,xCenter,0,w-xCenter,h), mMatrix, paint);

    canvas.setBitmap(cBitmap);
    canvas.drawBitmap(workLayer, new Matrix(), paint);

    Log.i("INFO","At 20, string measures: "+paint.measureText(message));
    canvas = null;
    workLayer = null;
    textLayer = null;
    System.gc();
    makeFileAndIntent();

}

Here is my LogCat info:

01-11 04:05:26.615: D/AndroidRuntime(314): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
01-11 04:05:26.615: D/AndroidRuntime(314): CheckJNI is ON
01-11 04:05:26.705: D/AndroidRuntime(314): --- registering native functions ---
01-11 04:05:27.095: D/AndroidRuntime(314): Shutting down VM
01-11 04:05:27.095: D/dalvikvm(314): Debugger has detached; object registry had 1 entries
01-11 04:05:27.105: I/AndroidRuntime(314): NOTE: attach of thread 'Binder Thread #3' failed
01-11 04:05:27.415: D/AndroidRuntime(322): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
01-11 04:05:27.415: D/AndroidRuntime(322): CheckJNI is ON
01-11 04:05:27.515: D/AndroidRuntime(322): --- registering native functions ---
01-11 04:05:27.905: I/ActivityManager(59): Force stopping package com.gigabites.fortune uid=10040
01-11 04:05:27.905: I/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.gigabites.fortune/.BuildActivity }
01-11 04:05:27.925: I/ActivityManager(59): Start proc com.gigabites.fortune for activity com.gigabites.fortune/.BuildActivity: pid=328 uid=10040 gids={1015}
01-11 04:05:27.945: W/WindowManager(59): HistoryRecord{450b8ef0 com.gigabites.fortune/.BuildActivity} failed creating starting window
01-11 04:05:27.945: W/WindowManager(59): android.view.InflateException: Binary XML file line #24: Error inflating class <unknown>
01-11 04:05:27.945: W/WindowManager(59):    at android.view.LayoutInflater.createView(LayoutInflater.java:513)
01-11 04:05:27.945: W/WindowManager(59):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
01-11 04:05:27.945: W/WindowManager(59):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
01-11 04:05:27.945: W/WindowManager(59):    at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
01-11 04:05:27.945: W/WindowManager(59):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-11 04:05:27.945: W/WindowManager(59):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-11 04:05:27.945: W/WindowManager(59):    at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2165)
01-11 04:05:27.945: W/WindowManager(59):    at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2220)
01-11 04:05:27.945: W/WindowManager(59):    at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1407)
01-11 04:05:27.945: W/WindowManager(59):    at com.android.internal.policy.impl.PhoneWindowManager.addStartingWindow(PhoneWindowManager.java:894)
01-11 04:05:27.945: W/WindowManager(59):    at com.android.server.WindowManagerService$H.handleMessage(WindowManagerService.java:9007)
01-11 04:05:27.945: W/WindowManager(59):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-11 04:05:27.945: W/WindowManager(59):    at android.os.Looper.loop(Looper.java:123)
01-11 04:05:27.945: W/WindowManager(59):    at com.android.server.WindowManagerService$WMThread.run(WindowManagerService.java:570)
01-11 04:05:27.945: W/WindowManager(59): Caused by: java.lang.reflect.InvocationTargetException
01-11 04:05:27.945: W/WindowManager(59):    at android.widget.FrameLayout.<init>(FrameLayout.java:79)
01-11 04:05:27.945: W/WindowManager(59):    at java.lang.reflect.Constructor.constructNative(Native Method)
01-11 04:05:27.945: W/WindowManager(59):    at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
01-11 04:05:27.945: W/WindowManager(59):    at android.view.LayoutInflater.createView(LayoutInflater.java:500)
01-11 04:05:27.945: W/WindowManager(59):    ... 13 more
01-11 04:05:27.945: W/WindowManager(59): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x1010059 a=-1}
01-11 04:05:27.945: W/WindowManager(59):    at android.content.res.Resources.loadDrawable(Resources.java:1681)
01-11 04:05:27.945: W/WindowManager(59):    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
01-11 04:05:27.945: W/WindowManager(59):    at android.widget.FrameLayout.<init>(FrameLayout.java:91)
01-11 04:05:27.945: W/WindowManager(59):    ... 17 more
01-11 04:05:27.955: D/AndroidRuntime(322): Shutting down VM
01-11 04:05:27.955: D/dalvikvm(322): Debugger has detached; object registry had 1 entries
01-11 04:05:27.975: I/dalvikvm(322): JNI: AttachCurrentThread (from ???.???)
01-11 04:05:27.975: I/AndroidRuntime(322): NOTE: attach of thread 'Binder Thread #3' failed
01-11 04:05:28.105: W/ActivityThread(328): Application com.gigabites.fortune is waiting for the debugger on port 8100...
01-11 04:05:28.135: I/System.out(328): Sending WAIT chunk
01-11 04:05:28.145: I/dalvikvm(328): Debugger is active
01-11 04:05:28.335: I/System.out(328): Debugger has connected
01-11 04:05:28.335: I/System.out(328): waiting for debugger to settle...
01-11 04:05:28.535: I/System.out(328): waiting for debugger to settle...
01-11 04:05:28.782: I/System.out(328): waiting for debugger to settle...
01-11 04:05:28.975: I/System.out(328): waiting for debugger to settle...
01-11 04:05:29.185: I/System.out(328): waiting for debugger to settle...
01-11 04:05:29.385: I/System.out(328): waiting for debugger to settle...
01-11 04:05:29.607: I/System.out(328): waiting for debugger to settle...
01-11 04:05:29.805: I/System.out(328): waiting for debugger to settle...
01-11 04:05:30.021: I/System.out(328): waiting for debugger to settle...
01-11 04:05:30.229: I/System.out(328): waiting for debugger to settle...
01-11 04:05:30.445: I/System.out(328): debugger has settled (1388)
01-11 04:05:33.015: I/INFO(328): At 2###########
01-11 04:05:34.585: I/ActivityManager(59): Displayed activity com.gigabites.fortune/.BuildActivity: 6668 ms (total 6668 ms)
01-11 04:05:37.678: I/INFO(328): At 1###########
01-11 04:05:37.785: D/dalvikvm(328): GC_EXTERNAL_ALLOC freed 1191 objects / 77104 bytes in 40ms
01-11 04:05:37.875: I/INFO(328): At 2###########
01-11 04:05:37.885: I/INFO(328): At 20, string measures: 653.0
01-11 04:05:37.925: D/dalvikvm(328): GC_EXTERNAL_ALLOC freed 360 objects / 16904 bytes in 35ms
01-11 04:05:37.985: D/dalvikvm(328): GC_EXTERNAL_ALLOC freed 47 objects / 1776 bytes in 35ms
01-11 04:05:38.055: I/INFO(328): At before first draw ###########
01-11 04:05:38.135: D/dalvikvm(328): GC_EXTERNAL_ALLOC freed 15 objects / 632 bytes in 30ms
01-11 04:05:38.196: D/dalvikvm(328): GC_EXPLICIT freed 12 objects / 424 bytes in 31ms
01-11 04:05:38.345: I/DEBUG(31): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
01-11 04:05:38.345: I/DEBUG(31): Build fingerprint: 'generic/google_sdk/generic/:2.2/FRF91/43546:eng/test-keys'
01-11 04:05:38.345: I/DEBUG(31): pid: 328, tid: 335  >>> com.gigabites.fortune <<<
01-11 04:05:38.345: I/DEBUG(31): signal 11 (SIGSEGV), fault addr deadbaad
01-11 04:05:38.345: I/DEBUG(31):  r0 00000000  r1 0000000c  r2 00000027  r3 00000000
01-11 04:05:38.345: I/DEBUG(31):  r4 00000000  r5 deadbaad  r6 00001728  r7 00000000
01-11 04:05:38.345: I/DEBUG(31):  r8 46d00d10  r9 4185ef74  10 002404e8  fp 4185ef70
01-11 04:05:38.345: I/DEBUG(31):  ip ffffffff  sp 46d00c80  lr afd154c5  pc afd11dc4  cpsr 40000030
01-11 04:05:38.415: I/DEBUG(31):          #00  pc 00011dc4  /system/lib/libc.so
01-11 04:05:38.415: I/DEBUG(31):          #01  pc 0000be1c  /system/lib/libc.so
01-11 04:05:38.415: I/DEBUG(31): code around pc:
01-11 04:05:38.415: I/DEBUG(31): afd11da4 1c2bd00b 2d00682d e026d1fb 2b0068db 
01-11 04:05:38.415: I/DEBUG(31): afd11db4 4e17d003 51a02001 4d164798 24002227 
01-11 04:05:38.415: I/DEBUG(31): afd11dc4 f7fb702a 2106ee14 ef10f7fc 05592380 
01-11 04:05:38.415: I/DEBUG(31): afd11dd4 6091aa01 1c116054 94012006 eab6f7fc 
01-11 04:05:38.415: I/DEBUG(31): afd11de4 2200a905 f7fc2002 f7fbeac2 2106ee00 
01-11 04:05:38.415: I/DEBUG(31): code around lr:
01-11 04:05:38.415: I/DEBUG(31): afd154a4 b0834a0d 589c447b 26009001 686768a5 
01-11 04:05:38.415: I/DEBUG(31): afd154b4 220ce008 2b005eab 1c28d003 47889901 
01-11 04:05:38.415: I/DEBUG(31): afd154c4 35544306 d5f43f01 2c006824 b003d1ee 
01-11 04:05:38.415: I/DEBUG(31): afd154d4 bdf01c30 0002ae7c 000000d4 1c0fb5f0 
01-11 04:05:38.415: I/DEBUG(31): afd154e4 43551c3d a904b087 1c16ac01 604d9004 
01-11 04:05:38.415: I/DEBUG(31): stack:
01-11 04:05:38.415: I/DEBUG(31):     46d00c40  00000015  
01-11 04:05:38.415: I/DEBUG(31):     46d00c44  afd1453b  /system/lib/libc.so
01-11 04:05:38.415: I/DEBUG(31):     46d00c48  afd405a0  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c4c  afd4054c  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c50  00000000  
01-11 04:05:38.426: I/DEBUG(31):     46d00c54  afd154c5  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c58  00000000  
01-11 04:05:38.426: I/DEBUG(31):     46d00c5c  afd1450d  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c60  afd41724  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c64  afd40328  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c68  00000000  
01-11 04:05:38.426: I/DEBUG(31):     46d00c6c  00001728  
01-11 04:05:38.426: I/DEBUG(31):     46d00c70  00000000  
01-11 04:05:38.426: I/DEBUG(31):     46d00c74  afd147ab  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c78  df002777  
01-11 04:05:38.426: I/DEBUG(31):     46d00c7c  e3a070ad  
01-11 04:05:38.426: I/DEBUG(31): #00 46d00c80  8086caa4  /system/lib/libdvm.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c84  80870eea  /system/lib/libdvm.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c88  afd418dc  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c8c  afd10510  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c90  afd40328  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c94  fffffbdf  
01-11 04:05:38.426: I/DEBUG(31):     46d00c98  afd40328  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c9c  afd41724  /system/lib/libc.so
01-11 04:05:38.435: I/DEBUG(31):     46d00ca0  0000a000  [heap]
01-11 04:05:38.435: I/DEBUG(31):     46d00ca4  afd0be21  /system/lib/libc.so
01-11 04:05:38.435: I/DEBUG(31): #01 46d00ca8  afd40328  /system/lib/libc.so
01-11 04:05:38.435: I/DEBUG(31):     46d00cac  afd0be21  /system/lib/libc.so
01-11 04:05:38.435: I/DEBUG(31):     46d00cb0  418cb358  /dev/ashmem/dalvik-LinearAlloc (deleted)
01-11 04:05:38.435: I/DEBUG(31):     46d00cb4  80846dad  /system/lib/libdvm.so
01-11 04:05:38.435: I/DEBUG(31):     46d00cb8  00119ab8  [heap]
01-11 04:05:38.435: I/DEBUG(31):     46d00cbc  00234078  [heap]
01-11 04:05:38.435: I/DEBUG(31):     46d00cc0  44ef45a8  /dev/ashmem/mspace/dalvik-heap/2 (deleted)
01-11 04:05:38.435: I/DEBUG(31):     46d00cc4  8083d9b9  /system/lib/libdvm.so
01-11 04:05:38.435: I/DEBUG(31):     46d00cc8  000013fc  
01-11 04:05:38.435: I/DEBUG(31):     46d00ccc  00234608  [heap]
01-11 04:05:38.435: I/DEBUG(31):     46d00cd0  44ef45a8  /dev/ashmem/mspace/dalvik-heap/2 (deleted)
01-11 04:05:38.435: I/DEBUG(31):     46d00cd4  00119ab8  [heap]
01-11 04:05:38.435: I/DEBUG(31):     46d00cd8  afd417e0  /system/lib/libc.so
01-11 04:05:38.435: I/DEBUG(31):     46d00cdc  42c3d5f6  /data/dalvik-cache/system@framework@framework.jar@classes.dex
01-11 04:05:38.435: I/DEBUG(31):     46d00ce0  4185ef7c  
01-11 04:05:38.435: I/DEBUG(31):     46d00ce4  afd0cd81  /system/lib/libc.so
01-11 04:05:38.435: I/DEBUG(31):     46d00ce8  00119ab8  [heap]
01-11 04:05:38.435: I/DEBUG(31):     46d00cec  afc008e3  /system/lib/libstdc++.so
01-11 04:05:38.855: I/BootReceiver(59): Copying /data/tombstones/tombstone_08 to DropBox (SYSTEM_TOMBSTONE)
01-11 04:05:38.875: D/Zygote(33): Process 328 terminated by signal (11)
01-11 04:05:38.955: D/dalvikvm(59): GC_FOR_MALLOC freed 2276 objects / 507544 bytes in 99ms
01-11 04:05:38.955: I/ActivityManager(59): Process com.gigabites.fortune (pid 328) has died.
01-11 04:05:38.965: I/WindowManager(59): WIN DEATH: Window{45087aa8 com.gigabites.fortune/com.gigabites.fortune.BuildActivity paused=false}
01-11 04:05:38.975: I/UsageStats(59): Unexpected resume of com.android.launcher while already resumed in com.gigabites.fortune
01-11 04:05:39.055: D/dalvikvm(59): GC_FOR_MALLOC freed 512 objects / 159856 bytes in 66ms
01-11 04:05:39.156: W/InputManagerService(59): Got RemoteException sending setActive(false) notification to pid 328 uid 10040

My android emulator heap size is 24 When I run this on my galaxy vibrant everything seems to work fine.

Here is my XML for landingscreen layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" android:background="@color/maroon" android:gravity="center">

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="@drawable/darkred_maroon_gradient" >

        <TextView
                    android:id="@+id/titlebar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="12sp"
                    android:textAppearance="?android:attr/textAppearanceSmall" android:text="@string/app_name" android:background="@drawable/darkred_maroon_gradient" android:paddingLeft="5dp" android:textColor="@color/yellow" android:typeface="monospace" android:gravity="left|center_vertical"/>
        <TextView
                    android:id="@+id/titlebar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="12sp"
                    android:textAppearance="?android:attr/textAppearanceSmall" android:text="GiGA BiTES" android:gravity="right|center_vertical" android:paddingRight="5dp" android:textColor="@color/yellow" android:typeface="monospace"/>
    </LinearLayout>

    <TableLayout
        android:id="@+id/tableLayout1"
        android:weightSum="2"
        android:layout_width="match_parent"

        android:layout_height="match_parent" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_weight="1"
            android:layout_height="wrap_content" android:weightSum="2">

            <RelativeLayout 
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" android:layout_weight="1"
                android:gravity="center" android:layout_gravity="center">

                <ImageView
                    android:id="@+id/ncview"
                    android:onClick="onClick"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" android:src="@drawable/newcicon" android:scaleType="center" android:layout_centerHorizontal="true" android:paddingTop="3dp"/>
                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/newc"
                    android:onClick="onClick"
                    android:textAppearance="?android:attr/textAppearanceLarge" android:layout_centerInParent="true" android:textColor="@color/yellow"/>
            </RelativeLayout>
            <RelativeLayout 
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" android:layout_weight="1" android:gravity="center">
                <ImageView
                    android:id="@+id/scview"
                    android:onClick="onClick"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" android:src="@drawable/sendcicon" android:scaleType="center" android:layout_centerHorizontal="true"/>

                <TextView
                    android:onClick="onClick"
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/sendc" 
                    android:textAppearance="?android:attr/textAppearanceLarge" android:layout_centerInParent="true" android:textColor="@color/yellow"/>

            </RelativeLayout>

        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:layout_weight="1"
            android:weightSum="2">

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:orientation="vertical" android:layout_weight="1" android:gravity="center" android:layout_gravity="bottom">
                <ImageView
                    android:id="@+id/ctview"
                    android:onClick="onClick"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:scaleType="center"
                    android:src="@drawable/cticon" android:layout_centerHorizontal="true" android:paddingTop="25dp"/>
                <TextView
                    android:onClick="onClick"
                    android:id="@+id/textView3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/buytokens" 
                    android:textAppearance="?android:attr/textAppearanceLarge" android:layout_gravity="bottom|center_horizontal" android:layout_centerInParent="true" android:gravity="center" android:textColor="@color/yellow"/>
            </RelativeLayout>
            <RelativeLayout 
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:orientation="vertical" android:layout_weight="1" android:gravity="center">
                <ImageView
                    android:id="@+id/hview"
                    android:onClick="onClick"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:scaleType="center"
                    android:src="@drawable/helpicon" android:layout_centerHorizontal="true"/>
                <TextView
                    android:id="@+id/textView4"
                    android:onClick="onClick"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/help"
                    android:textAppearance="?android:attr/textAppearanceLarge" android:layout_centerInParent="true" android:textColor="@color/yellow"/>
            </RelativeLayout>


        </TableRow>

    </TableLayout>

</LinearLayout>

Also, I tried this on an emulator with a heap size of 32 and still had the same problem.

UPDATE: I have now tried this bitmap creation in the doInBackground of an AsyncTask object and got the same problem

Also, I wanted to point out that I am now loading the reasource from a drawable-nodpi folder so that the emulator doesn't do any resizing and still having problems.

Foi útil?

Solução

Bitmaps in Android are problematic for garbage collection. The Java Bitmap object is just a handle to a native object that does the real work of handling the objects. The native object is stored outside of the Java heap, and therefore it is not handled by the garbage collector.

Once a Java Bitmap object is garbage collected, it will release the native object. However the Java object is much smaller than the bitmap data, so if you keep making new Java Bitmap instances the native heap will fill up before GC is invoked, even if you release the references to the objects. Since the native heap knows nothing about the Java heap when it gets too full, rather than invoking GC it will simply bomb.

The key to avoiding this situation is to call Bitmap.recycle() when you finish using the Java object to release the native object, just as you would if you were using C++. Unfortunately Java has no support for destructors or smart pointers, so you just have to rely on programmer discipline.

In your case the calls to recycle() are made by Camera, so that's why your fix worked.

Outras dicas

I was getting the error because I was not balancing every Camera.save() call with a Camera.restore() call.

When I had the problem with large heap, I went to emulator defining and changed the memory size there. The default memory is very small, as I remember. And your 32 are not much, either. Why you are limiting yourself so?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top