java.lang.OutOfMemoryError:pthread_create(1040KB堆栈)失败:改造后重试

时间:2019-11-13 13:21:49

标签: android retrofit2 okhttp

 **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)

在应用停留模式下,有时应用会崩溃。

1 个答案:

答案 0 :(得分:0)

尝试这种方式:

在AndroidManifest.xml中

1-设置android:largeHeap="true"

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

3-及在build.gradle上:

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