内存不足错误:Java堆内存(GC堆)

时间:2018-10-11 07:17:33

标签: java android garbage-collection out-of-memory

突然我的应用程序崩溃并弹出此错误...对此错误有任何想法吗?这么努力仍然无法解决...

Clamp target GC heap from 111MB to 96MB Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 2.380ms total 71.136ms

  

Throwing OutOfMemoryError“未能分配14710字节的分配,其中包含12888个可用字节和12KB,直到OOM为止

AndroidRuntime: Error reporting crash
              java.lang.OutOfMemoryError: Failed to allocate a 14710 byte allocation with 12888 free bytes and 12KB until OOM
                  at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:95)
                  at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:125)
                  at java.lang.StringBuffer.append(StringBuffer.java:278)
                  at java.io.StringWriter.write(StringWriter.java:123)
                  at com.android.internal.util.FastPrintWriter.flushLocked(FastPrintWriter.java:358)
                  at com.android.internal.util.FastPrintWriter.appendLocked(FastPrintWriter.java:303)
                  at com.android.internal.util.FastPrintWriter.write(FastPrintWriter.java:625)
                  at com.android.internal.util.FastPrintWriter.append(FastPrintWriter.java:658)
                  at java.io.PrintWriter.append(PrintWriter.java:691)
                  at java.io.PrintWriter.append(PrintWriter.java:31)
                  at java.lang.Throwable.printStackTrace(Throwable.java:324)
                  at java.lang.Throwable.printStackTrace(Throwable.java:300)
                  at android.util.Log.getStackTraceString(Log.java:509)
                  at com.android.internal.os.RuntimeInit.Clog_e(RuntimeInit.java:59)
                  at com.android.internal.os.RuntimeInit.access$200(RuntimeInit.java:43)
                  at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:91)
                  at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
                  at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)

我尝试过类似thisthisthis之类的方法,但是它不起作用。

有人可以帮我解决吗?我真的很感激。

谢谢!

1 个答案:

答案 0 :(得分:2)

在您的Manifext.xml中添加此行android:largeHeap="true",它将分配一个大的堆内存。

<application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"

        android:largeHeap="true"

        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/MyAppTheme">
...
</application>

我希望这对您有用。

尝试使用 Debugger和Android Profiler 来检测确切用于提高性能的资源。