【问题标题】:java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again in retrofitjava.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: 在改造中重试
【发布时间】:2019-11-13 21:50:22
【问题描述】:
 **java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again**
       at java.lang.Thread.nativeCreate(Native Method)
       at java.lang.Thread.start(Thread.java:730)
       at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:941)
       at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1359)
       at okhttp3.Dispatcher.enqueue(Dispatcher.java:129)
       at okhttp3.RealCall.enqueue(RealCall.java:78)
       at retrofit2.OkHttpCall.enqueue(OkHttpCall.java:101)

当应用程序保持模式时,有时应用程序会崩溃。

【问题讨论】:

  • 您是否为每个请求创建新的OkHttpClient 对象?

标签: android retrofit2 okhttp


【解决方案1】:

试试这个方法:

1- 在 AndroidManifest.xml 上设置android:largeHeap="true"

2- 在gradle.properties 上将org.gradle.jvmargs=-Xmx1536m 更改为org.gradle.jvmargs=-Xmx4608m

3- 并在 build.gradle 上:

android {
    dexOptions {
        incremental true
        javaMaxHeapSize "4g"
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-07
    • 1970-01-01
    相关资源
    最近更新 更多