有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

突然我的应用程序崩溃并弹出此错误。。。你知道这个错误吗?这么努力还是解决不了

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 "Failed to allocate a 14710 byte allocation with 12888 free bytes and 12KB until 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.安卓.internal.util.FastPrintWriter.flushLocked(FastPrintWriter.java:358)
                  at com.安卓.internal.util.FastPrintWriter.appendLocked(FastPrintWriter.java:303)
                  at com.安卓.internal.util.FastPrintWriter.write(FastPrintWriter.java:625)
                  at com.安卓.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 安卓.util.Log.getStackTraceString(Log.java:509)
                  at com.安卓.internal.os.RuntimeInit.Clog_e(RuntimeInit.java:59)
                  at com.安卓.internal.os.RuntimeInit.access$200(RuntimeInit.java:43)
                  at com.安卓.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) 个答案

  1. # 1 楼答案

    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>
    

    我希望这对你有用

    尝试使用调试器和Android Profiler来检测用于提高性能的资源的确切位置