运行我的应用程序时,有50%的时间出现此错误

06-20 12:56:51.183: A/libc(32140): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 32140 (example.www)

我只需要重新打开该应用程序,然后它就可以工作了。但是我不知道为什么会收到此错误,导致应用程序崩溃。
我正在处理尺寸约为1200x1200px的大图像,并将其设置为背景。我还将该图像用作其他 Activity 作为背景的位图。还对服务器进行一些调用,并取回JSON数据。
希望我能提供足够的信息,因为我不知道要寻找什么...
我正在为4.1.2开发

完成Logcat
   06-20 13:02:38.823: W/ActivityThread(4102): Application eu.sexample.www can be debugged on port 8100...
06-20 13:02:38.983: D/dalvikvm(4102): GC_FOR_ALLOC freed 114K, 7% free 12283K/13191K, paused 13ms, total 13ms
06-20 13:02:38.988: I/dalvikvm-heap(4102): Grow heap (frag case) to 18.398MB for 5954576-byte allocation
06-20 13:02:39.008: D/dalvikvm(4102): GC_CONCURRENT freed 1K, 5% free 18096K/19015K, paused 12ms+1ms, total 22ms
06-20 13:02:39.053: D/dalvikvm(4102): GC_FOR_ALLOC freed 0K, 5% free 18097K/19015K, paused 10ms, total 10ms
06-20 13:02:39.088: I/dalvikvm-heap(4102): Grow heap (frag case) to 41.112MB for 23818256-byte allocation
06-20 13:02:39.103: D/dalvikvm(4102): GC_CONCURRENT freed 0K, 3% free 41357K/42311K, paused 3ms+1ms, total 16ms
06-20 13:02:39.168: D/dalvikvm(4102): GC_FOR_ALLOC freed 5815K, 16% free 35916K/42695K, paused 10ms, total 10ms
06-20 13:02:39.193: E/Location(4102): 51.1878642, 4.3802626
06-20 13:02:39.283: D/libEGL(4102): loaded /system/lib/egl/libEGL_mali.so
06-20 13:02:39.283: D/libEGL(4102): loaded /system/lib/egl/libGLESv1_CM_mali.so
06-20 13:02:39.288: D/libEGL(4102): loaded /system/lib/egl/libGLESv2_mali.so
06-20 13:02:39.288: D/(4102): Device driver API match
06-20 13:02:39.288: D/(4102): Device driver API version: 10
06-20 13:02:39.288: D/(4102): User space API version: 10
06-20 13:02:39.288: D/(4102): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct 16 15:37:13 KST 2012
06-20 13:02:39.323: D/OpenGLRenderer(4102): Enabling debug mode 0
06-20 13:02:42.413: D/dalvikvm(4102): GC_FOR_ALLOC freed 448K, 14% free 37130K/42695K, paused 13ms, total 13ms
06-20 13:02:42.423: I/dalvikvm-heap(4102): Grow heap (frag case) to 42.664MB for 5954576-byte allocation
06-20 13:02:42.433: D/dalvikvm(4102): GC_CONCURRENT freed 4K, 12% free 42941K/48519K, paused 2ms+2ms, total 13ms
06-20 13:02:42.478: D/dalvikvm(4102): GC_FOR_ALLOC freed 0K, 12% free 42941K/48519K, paused 10ms, total 10ms
06-20 13:02:42.478: I/dalvikvm-heap(4102): Forcing collection of SoftReferences for 23818256-byte allocation
06-20 13:02:42.498: D/dalvikvm(4102): GC_BEFORE_OOM freed 9K, 12% free 42931K/48519K, paused 19ms, total 19ms
06-20 13:02:42.498: E/dalvikvm-heap(4102): Out of memory on a 23818256-byte allocation.
06-20 13:02:42.498: I/dalvikvm(4102): "main" prio=5 tid=1 RUNNABLE
06-20 13:02:42.498: I/dalvikvm(4102):   | group="main" sCount=0 dsCount=0 obj=0x41585508 self=0x415758c8
06-20 13:02:42.498: I/dalvikvm(4102):   | sysTid=4102 nice=0 sched=0/0 cgrp=apps handle=1074532144
06-20 13:02:42.498: I/dalvikvm(4102):   | schedstat=( 2709445063 154759556 1906 ) utm=227 stm=43 core=2
06-20 13:02:42.498: I/dalvikvm(4102):   at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
06-20 13:02:42.498: I/dalvikvm(4102):   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:623)
06-20 13:02:42.498: I/dalvikvm(4102):   at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:476)
06-20 13:02:42.503: I/dalvikvm(4102):   at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
06-20 13:02:42.503: I/dalvikvm(4102):   at android.content.res.Resources.loadDrawable(Resources.java:1963)
06-20 13:02:42.503: I/dalvikvm(4102):   at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
06-20 13:02:42.503: I/dalvikvm(4102):   at android.view.View.<init>(View.java:3436)
06-20 13:02:42.503: I/dalvikvm(4102):   at android.view.View.<init>(View.java:3371)
06-20 13:02:42.503: I/dalvikvm(4102):   at android.view.ViewGroup.<init>(ViewGroup.java:426)
06-20 13:02:42.503: I/dalvikvm(4102):   at android.widget.RelativeLayout.<init>(RelativeLayout.java:184)
06-20 13:02:42.503: I/dalvikvm(4102):   at java.lang.reflect.Constructor.constructNative(Native Method)
06-20 13:02:42.503: I/dalvikvm(4102):   at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.view.LayoutInflater.createView(LayoutInflater.java:587)
06-20 13:02:42.508: I/dalvikvm(4102):   at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-20 13:02:42.508: I/dalvikvm(4102):   at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.app.Activity.setContentView(Activity.java:1924)
06-20 13:02:42.508: I/dalvikvm(4102):   at eu.sexample.www.MainActivity.onCreate(MainActivity.java:28)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.app.Activity.performCreate(Activity.java:5206)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.app.ActivityThread.access$600(ActivityThread.java:140)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.os.Handler.dispatchMessage(Handler.java:99)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.os.Looper.loop(Looper.java:137)
06-20 13:02:42.508: I/dalvikvm(4102):   at android.app.ActivityThread.main(ActivityThread.java:4898)
06-20 13:02:42.508: I/dalvikvm(4102):   at java.lang.reflect.Method.invokeNative(Native Method)
06-20 13:02:42.508: I/dalvikvm(4102):   at java.lang.reflect.Method.invoke(Method.java:511)
06-20 13:02:42.513: I/dalvikvm(4102):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
06-20 13:02:42.513: I/dalvikvm(4102):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
06-20 13:02:42.513: I/dalvikvm(4102):   at dalvik.system.NativeStart.main(Native Method)
06-20 13:02:42.513: A/libc(4102): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 4102 (example.www)

最佳答案

真正的错误是Out of memory on a 23818256-byte allocation。您正在尝试分配〜22MB的内存块,并且没有足够的可用内存,更不用说这么大的连续块了。

在这种情况下,它来自可绘制资源。大约22MB是一个真正的庞大图像,比1200x1200更像2400x2400。

您的进程堆大小为48MB,这是很大的,但是〜22MB几乎是堆预​​算的一半。

我建议您找出这是哪个可绘制资源(看起来可能是RelativeLayout的背景),然后减小其大小和相似图像的大小。在这里,“大小”是指总像素数,而不是磁盘上的大小,因为重要的是RAM中的解压缩大小,而不是磁盘上的图像大小。

同样,这可能是资源目录的问题。例如,如果将1200x1200图像放在res/drawable/中,则实际上就是res/drawable-mdpi/的同义词。如果此设备恰好是-xhdpi设备,则可以解释内存使用情况,因为Android会尝试对该图像进行升采样并将每个尺寸加倍。

10-07 18:41