我环顾四周,从其他人的帖子中我认为这个错误是因为我的活动可能超出了堆限制。我正在操作一些位图并应用技术来减少我的应用程序的堆大小,例如不使用Bitmap.createBitmap(),而是将一个小位图放大为空白位图进行修改。我也在创建的位图上使用inPurgable选项。这是我的代码。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("INFO","At 2###########");
setContentView(R.layout.landingscreen);
Thread thread = new Thread(this);
thread.start();
}
我的活动实现了Runnable,这是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();
}
这是我的LogCat信息:
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
我的android模拟器堆大小是24 当我在银河系中运行时,一切看起来都很好。
这是我的用于登陆屏幕布局的XML
<?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>
另外,我在堆大小为32的仿真器上尝试了这个并且仍然遇到了同样的问题。
更新:我现在尝试在AsyncTask对象的doInBackground中创建这个位图并遇到同样的问题
另外,我想指出我现在正在从drawable-nodpi文件夹加载reasource,以便模拟器不会进行任何调整大小并且仍然存在问题。
答案 0 :(得分:6)
Android中的位图对于垃圾收集存在问题。 Java Bitmap对象只是本机对象的句柄,它可以完成处理对象的实际工作。本机对象存储在Java堆之外,因此它不由垃圾收集器处理。
一旦Java Bitmap对象被垃圾收集,它将释放本机对象。但是,Java对象比位图数据小得多,因此,如果继续创建新的Java Bitmap实例,则在调用GC之前,本机堆将填满,即使您释放对对象的引用也是如此。由于本机堆在Java堆太满时对Java堆一无所知,而不是调用GC它只会炸弹。
避免这种情况的关键是在完成使用Java对象释放本机对象时调用Bitmap.recycle()
,就像使用C ++一样。不幸的是,Java不支持析构函数或智能指针,所以你只需要依赖程序员纪律。
在你的情况下,对recycle()的调用是由Camera进行的,这就是你的修复工作的原因。
答案 1 :(得分:1)
我收到错误是因为我没有使用Camera.restore()调用来平衡每个Camera.save()调用。
答案 2 :(得分:0)
当我遇到大堆的问题时,我去了模拟器定义并更改了那里的内存大小。我记得,默认内存非常小。你的32也不多。你为什么限制自己?