0

当重复脉冲按钮移动我在应用程序中时,总是会出现这种内存错误。

我已经检查过它是否在同一个按钮上被多次单击,我还设置了一个条件,即不加载另一个意图来打开另一个活动,直到你不使电流过载。但这不是这个原因。

在我的许多活动中加载许多在滚动视图中膨胀的视图。

对于空闲内存,我试过这个:

在更改活动之前,我执行此视图是一个 android:id 每个活动中使用的布局。

1.-

if (view.getBackground() != null) {
    view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup) {
    for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
        unbindDrawables(((ViewGroup) view).getChildAt(i));
    }
    ((ViewGroup) view).removeAllViews();
}

2.-

System.gc();

但这似乎还不够。这是我的LogCat:

11-06 09:23:34.480: I/dalvikvm-heap(9160): Grow heap (frag case) to 39.174MB for 3133456-byte allocation
11-06 09:23:34.519: D/dalvikvm(9160): GC_CONCURRENT freed 5K, 33% free 40059K/59463K, paused 13ms+7ms, total 43ms
11-06 09:23:34.613: D/dalvikvm(9160): GC_FOR_ALLOC freed 0K, 33% free 40059K/59463K, paused 24ms, total 24ms
11-06 09:23:34.613: I/dalvikvm-heap(9160): Forcing collection of SoftReferences for 12533776-byte allocation
11-06 09:23:34.652: D/dalvikvm(9160): GC_BEFORE_OOM freed 0K, 33% free 40059K/59463K, paused 39ms, total 39ms
11-06 09:23:34.652: E/dalvikvm-heap(9160): Out of memory on a 12533776-byte allocation.
11-06 09:23:34.660: I/dalvikvm(9160): "main" prio=5 tid=1 RUNNABLE
11-06 09:23:34.660: I/dalvikvm(9160):   | group="main" sCount=0 dsCount=0 obj=0x40c7c568 self=0x40bbcab0
11-06 09:23:34.660: I/dalvikvm(9160):   | sysTid=9160 nice=0 sched=0/0 cgrp=apps handle=1075234352
11-06 09:23:34.660: I/dalvikvm(9160):   | schedstat=( 0 0 0 ) utm=2490 stm=234 core=1
11-06 09:23:34.660: I/dalvikvm(9160):   at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:500)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:353)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.content.res.Resources.loadDrawable(Resources.java:1930)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.view.View.<init>(View.java:3336)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.view.ViewGroup.<init>(ViewGroup.java:427)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.widget.LinearLayout.<init>(LinearLayout.java:176)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.widget.LinearLayout.<init>(LinearLayout.java:172)
11-06 09:23:34.660: I/dalvikvm(9160):   at java.lang.reflect.Constructor.constructNative(Native Method)
11-06 09:23:34.660: I/dalvikvm(9160):   at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.view.LayoutInflater.createView(LayoutInflater.java:587)
11-06 09:23:34.660: I/dalvikvm(9160):   at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-06 09:23:34.660: I/dalvikvm(9160):   at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.app.Activity.setContentView(Activity.java:1867)
11-06 09:23:34.660: I/dalvikvm(9160):   at com.hiberus.campus.seas.views.Estudios.onCreate(Estudios.java:81)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.app.Activity.performCreate(Activity.java:5008)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.app.ActivityThread.access$600(ActivityThread.java:130)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.os.Handler.dispatchMessage(Handler.java:99)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.os.Looper.loop(Looper.java:137)
11-06 09:23:34.660: I/dalvikvm(9160):   at android.app.ActivityThread.main(ActivityThread.java:4745)
11-06 09:23:34.660: I/dalvikvm(9160):   at java.lang.reflect.Method.invokeNative(Native Method)
11-06 09:23:34.660: I/dalvikvm(9160):   at java.lang.reflect.Method.invoke(Method.java:511)
11-06 09:23:34.660: I/dalvikvm(9160):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-06 09:23:34.660: I/dalvikvm(9160):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-06 09:23:34.660: I/dalvikvm(9160):   at dalvik.system.NativeStart.main(Native Method)
11-06 09:23:34.660: A/libc(9160): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 9160 (rus.campus.seas)

你怎么能解决这个问题?谢谢!

4

1 回答 1

2

在我的应用程序中,每个布局都有他的背景。给我错误的行总是“setContentView(R.layout.xxx)”,所以我减少了所有用作背景的图像,我已经解决了我的内存问题。

于 2012-11-06T10:30:00.517 回答