Okhttp: Fatal Exception: java.lang.OutOfMemoryError: Could not allocate JNI Env

Created on 27 Mar 2018  Â·  3Comments  Â·  Source: square/okhttp

Fatal Exception: java.lang.OutOfMemoryError: Could not allocate JNI Env
at java.lang.Thread.nativeCreate(Thread.java)
at java.lang.Thread.start(Thread.java:731)
at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:941)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1359)
at okhttp3.ConnectionPool.put(ConnectionPool.java:153)
at okhttp3.OkHttpClient$1.put(OkHttpClient.java:166)
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:265)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:134)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:113)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:143)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:762)

Most helpful comment

This is usually a strong indication that you are creating new instances of OkHttpClient rather than re-using a single instance. OkHttp restricts the number of threads it creates so the only way this can happen is if you were already close to OOM or you create hundreds or thousands of OkHttpClient instance.

All 3 comments

This is usually a strong indication that you are creating new instances of OkHttpClient rather than re-using a single instance. OkHttp restricts the number of threads it creates so the only way this can happen is if you were already close to OOM or you create hundreds or thousands of OkHttpClient instance.

Thank you, I need refactoring

Thank you, I need refactoring

If you have before and after refactoring code, can you please make a gist and link it. It would be really helpful. I am getting same error

Was this page helpful?
0 / 5 - 0 ratings