gpt4 book ai didi

android - 为什么解析 StackOverflowException 会抛出 OOM?

转载 作者:行者123 更新时间:2023-11-30 01:37:45 24 4
gpt4 key购买 nike

我注意到,应用程序用户收到错误消息:

Fatal Exception: java.lang.OutOfMemoryError: OutOfMemoryError thrown while trying to throw OutOfMemoryError; no stack available

因此,我编写了非常简单的应用程序:

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Log.d("TAG", "" + getFoo());
}

private int getFoo() {
return getBar();
}

private int getBar() {
return getFoo();
}
}

谁在解析 StackOverflowException 时抛出 OOM 我无法在日志中获取堆栈跟踪:

01-20 13:51:06.250 8134-8134/lt.neworld.java E/art: Throwing OutOfMemoryError "Failed to allocate a 16482048 byte allocation with 12515386 free bytes and 11MB until OOM"
01-20 13:51:06.250 8134-8134/lt.neworld.java E/AndroidRuntime: Error reporting crash
java.lang.OutOfMemoryError: Failed to allocate a 16482048 byte allocation with 12515386 free bytes and 11MB 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:340)
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:85)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)

知道如何修复该 OOM 或如何在产品中获取堆栈跟踪信息吗?

最佳答案

更新:

ThreadGroup group = new ThreadGroup("threadGroup");
new Thread(group, new Runnable() {
private void stackOverflow() {
stackOverflow();
}
@Override
public void run() {
stackOverflow();
}
}, "name", 20).start();

关于android - 为什么解析 StackOverflowException 会抛出 OOM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34919265/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com