2013-07-30 51 views
0

我有一個活動和4個選項卡Activities.In每個選項卡活動,我有畫廊,網格布,當我從製表活動回來我的主要活動我得到了OutOfMemory exception.In我所有的選項卡活動,我有大量的圖片。我已經從第5天strucked。請幫我me.Here是logcat中:越來越OutOfMemory例外?

07-30 17:28:42.375: I/dalvikvm-heap(18784): Forcing collection of SoftReferences for 16384016-byte allocation 
07-30 17:28:42.406: D/dalvikvm(18784): GC_BEFORE_OOM freed 1K, 34% free 40614K/61511K, paused 29ms, total 30ms 
07-30 17:28:42.406: 
E/dalvikvm-heap(18784): Out of memory on a 16384016-byte allocation. 
07-30 17:28:42.406: I/dalvikvm(18784): "main" prio=5 tid=1 RUNNABLE 
07-30 17:28:42.406: I/dalvikvm(18784): 
    | group="main" sCount=0 dsCount=0 obj=0x41f726a0 self=0x41f5f018 
07-30 17:28:42.406: I/dalvikvm(18784): 
    | sysTid=18784 nice=0 sched=0/0 cgrp=apps handle=1075198032 
07-30 17:28:42.406: I/dalvikvm(18784): 
| schedstat=(0 0 0) utm=219 stm=55 core=0 
07-30 17:28:42.406: I/dalvikvm(18784): 
    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 
07-30 17:28:42.406: I/dalvikvm(18784): 
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:592) 
07-30 17:28:42.406: I/dalvikvm(18784): 
    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:445) 
07-30 17:28:42.406: I/dalvikvm(18784): 
    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781) 
07-30 17:28:42.406: 
I/dalvikvm(18784): at android.content.res.Resources.loadDrawable(Resources.java:1963) 
07-30 17:28:42.406: 
I/dalvikvm(18784): at android.content.res.TypedArray.getDrawable(TypedArray.java:601) 
07-30 17:28:42.406: I/dalvikvm(18784): at android.view.View.<init>(View.java:3419) 
07-30 17:28:42.406: I/dalvikvm(18784): at android.view.View.<init>(View.java:3352) 
07-30 17:28:42.406: I/dalvikvm(18784): at android.view.ViewGroup.<init>(ViewGroup.java:426) 
07-30 17:28:42.406: I/dalvikvm(18784): at android.widget.RelativeLayout.<init>(RelativeLayout.java:184) 
07-30 17:28:42.406: I/dalvikvm(18784): at java.lang.reflect.Constructor.constructNative(Native Method) 
07-30 17:28:42.406: I/dalvikvm(18784): at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 
07-30 17:28:42.406: I/dalvikvm(18784): at android.view.LayoutInflater.createView(LayoutInflater.java:587) 
07-30 17:28:42.406: I/dalvikvm(18784): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
07-30 17:28:42.406: I/dalvikvm(18784): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660) 
07-30 17:28:42.406: I/dalvikvm(18784): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685) 
07-30 17:28:42.416: I/dalvikvm(18784): at android.view.LayoutInflater.inflate(LayoutInflater.java:466) 
07-30 17:28:42.416: I/dalvikvm(18784): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
07-30 17:28:42.416: I/dalvikvm(18784): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
07-30 17:28:42.416: I/dalvikvm(18784): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:306) 
07-30 17:28:42.416: I/dalvikvm(18784): at android.app.Activity.setContentView(Activity.java:1901) 
07-30 17:28:42.416: I/dalvikvm(18784): at com.inventit.commentu.CommentU_Activity.onCreate(CommentU_Activity.java:182) 
07-30 17:28:42.416: I/dalvikvm(18784): at android.app.Activity.performCreate(Activity.java:5048) 
07-30 17:28:42.416: I/dalvikvm(18784): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 
07-30 17:28:42.416: I/dalvikvm(18784): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2052) 
07-30 17:28:42.416: I/dalvikvm(18784): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2113) 
07-30 17:28:42.416: I/dalvikvm(18784): at android.app.ActivityThread.access$700(ActivityThread.java:139) 
07-30 17:28:42.416: I/dalvikvm(18784): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1224) 
07-30 17:28:42.416: I/dalvikvm(18784): at android.os.Handler.dispatchMessage(Handler.java:99) 
07-30 17:28:42.416: I/dalvikvm(18784): at android.os.Looper.loop(Looper.java:137) 
07-30 17:28:42.416: I/dalvikvm(18784): at android.app.ActivityThread.main(ActivityThread.java:4918) 
07-30 17:28:42.416: I/dalvikvm(18784): at java.lang.reflect.Method.invokeNative(Native Method) 
07-30 17:28:42.416: I/dalvikvm(18784): at java.lang.reflect.Method.invoke(Method.java:511) 
07-30 17:28:42.416: I/dalvikvm(18784): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004) 
07-30 17:28:42.416: I/dalvikvm(18784): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771) 
07-30 17:28:42.416: I/dalvikvm(18784): at dalvik.system.NativeStart.main(Native Method) 
07-30 17:28:42.416: A/libc(18784): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 18784 (ventit.commentu) 
07-30 17:28:42.416: A/libc(18784): Fatal signal 11 (SIGSEGV) at 0x007d0000 (code=1), thread 18799 (ventit.commentu) 
07-30 17:28:50.154: E/Trace(18971): error opening trace file: No such file or directory (2) 
07-30 17:28:50.154: D/ActivityThread(18971): setTargetHeapUtilization:0.25 
07-30 17:28:50.154: D/ActivityThread(18971): setTargetHeapIdealFree:8388608 
07-30 17:28:50.154: D/ActivityThread(18971): setTargetHeapConcurrentStart:2097152 
07-30 17:28:50.294: D/dalvikvm(18971): GC_FOR_ALLOC freed 76K, 23% free 16129K/20931K, paused 16ms, total 17ms 
07-30 17:28:50.334: I/dalvikvm-heap(18971): Grow heap (frag case) to 40.043MB for 16384016-byte allocation 

感謝提前。

+0

你創建位圖?發佈您的主要活動代碼。 –

+0

你正試圖分配16MB的內存。你在裝什麼? – Simon

+0

在我的主要活動我有背景圖片,背景圖像按鈕和我有30幅表情符號圖像列表。 – user2629279

回答

0

檢查從開發商的網站上的文章Managing Bitmap Memory

對於API < = 10:

On Android 2.3.3 (API level 10) and lower, using recycle() is recommended. If you're displaying large amounts of bitmap data in your app, you're likely to run into OutOfMemoryError errors. The recycle() method allows an app to reclaim memory as soon as possible.

Caution: You should use recycle() only when you are sure that the bitmap is no longer being used. If you call recycle() and later attempt to draw the bitmap, you will get the error: "Canvas: trying to use a recycled bitmap".

The following code snippet gives an example of calling recycle(). It uses reference counting (in the variables mDisplayRefCount and mCacheRefCount) to track whether a bitmap is currently being displayed or in the cache. The code recycles the bitmap when these conditions are met:

  • The reference count for both mDisplayRefCount and mCacheRefCount is 0.
  • The bitmap is not null, and it hasn't been recycled yet.

對於API> = 11:

Android 3.0 (API Level 11) introduces the BitmapFactory.Options.inBitmap field. If this option is set, decode methods that take the Options object will attempt to reuse an existing bitmap when loading content. This means that the bitmap's memory is reused, resulting in improved performance, and removing both memory allocation and de-allocation.

+0

以上的API級別10?我的應用程序從2.2以上運行。 – user2629279

+0

爲API> = 10,有一些也音符[上述文章]在考慮(http://developer.android.com/training/displaying-bitmaps/manage-memory.html#inBitmap)。如果您將API> = 8作爲目標,那麼您應該考慮使用這兩種方法,並通過在運行時檢查API來確定究竟使用什麼。 – Antonio

+0

我怎麼可以檢查,如果我的應用程序運行在API級別 – user2629279