title: Android OkHttp getting OutOfMemory error while making https calls
body: <p>I am using retrofit, okhttp to make network calls in my app.</p>
  
  <p>Recently app users are facing a strange OOM crash while making requests.</p>
  
  <p>The stacktrace for the issue is :</p>
  
  <pre><code>Caused by java.lang.OutOfMemoryError: Failed to allocate a 39950 byte allocation with 8388512 free bytes and 62MB until OOM
     at libcore.io.IoUtils$FileReader.(IoUtils.java)
     at libcore.io.IoUtils.readFileAsString(IoUtils.java:116)
     at com.android.org.conscrypt.CertPinManager.readPinFile(CertPinManager.java:120)
     at com.android.org.conscrypt.CertPinManager.ensureInitialized(CertPinManager.java:92)
     at com.android.org.conscrypt.CertPinManager.lookup(CertPinManager.java:136)
     at com.android.org.conscrypt.CertPinManager.isChainValid(CertPinManager.java:72)
     at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:302)
     at com.android.org.conscrypt.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:219)
     at com.android.org.conscrypt.Platform.checkServerTrusted(Platform.java:113)
     at com.android.org.conscrypt.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:525)
     at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(NativeCrypto.java)
     at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:302)
     at okhttp3.internal.connection.RealConnection.connectTls(SourceFile:241)
     at okhttp3.internal.connection.RealConnection.establishProtocol(SourceFile:198)
     at okhttp3.internal.connection.RealConnection.buildConnection(SourceFile:174)
     at okhttp3.internal.connection.RealConnection.connect(SourceFile:114)
     at okhttp3.internal.connection.StreamAllocation.findConnection(SourceFile:193)
     at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(SourceFile:129)
     at okhttp3.internal.connection.StreamAllocation.newStream(SourceFile:98)
     at okhttp3.internal.connection.ConnectInterceptor.intercept(SourceFile:42)
     at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:92)
     at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:67)
     at okhttp3.internal.cache.CacheInterceptor.intercept(SourceFile:109)
     at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:92)
     at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:67)
     at okhttp3.internal.http.BridgeInterceptor.intercept(SourceFile:93)
     at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:92)
     at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(SourceFile:124)
     at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:92)
     at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:67)
     at okhttp3.logging.HttpLoggingInterceptor.intercept(SourceFile:212)
     at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:92)
     at okhttp3.internal.http.RealInterceptorChain.proceed(SourceFile:67)
     at okhttp3.RealCall.getResponseWithInterceptorChain(SourceFile:170)
     at okhttp3.RealCall.execute(SourceFile:60)
     at retrofit2.OkHttpCall.execute(SourceFile:174)
     at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$RequestArbiter.request(SourceFile:171)
     at rx.internal.producers.ProducerArbiter.setProducer(SourceFile:126)
     at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$4.setProducer(SourceFile:158)
     at rx.Subscriber.setProducer(SourceFile:205)
     at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(SourceFile:152)
     at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(SourceFile:138)
     at rx.internal.operators.OnSubscribeLift.call(SourceFile:50)
     at rx.internal.operators.OnSubscribeLift.call(SourceFile:30)
     at rx.internal.operators.OnSubscribeLift.call(SourceFile:50)
     at rx.internal.operators.OnSubscribeLift.call(SourceFile:30)
     at rx.Observable.unsafeSubscribe(SourceFile:8460)
     at rx.internal.operators.OnSubscribeRedo$2.call(SourceFile:278)
     at rx.internal.schedulers.TrampolineScheduler$InnerCurrentThreadScheduler.enqueue(SourceFile:76)
     at rx.internal.schedulers.TrampolineScheduler$InnerCurrentThreadScheduler.schedule(SourceFile:55)
     at rx.internal.operators.OnSubscribeRedo$5.request(SourceFile:366)
     at rx.internal.operators.OperatorSubscribeOn$1$1$1.request(SourceFile:80)
     at rx.Subscriber.setProducer(SourceFile:211)
     at rx.internal.operators.OperatorSubscribeOn$1$1.setProducer(SourceFile:76)
     at rx.internal.operators.OnSubscribeRedo.call(SourceFile:358)
     at rx.internal.operators.OnSubscribeRedo.call(SourceFile:55)
     at rx.Observable.unsafeSubscribe(SourceFile:8460)
     at rx.internal.operators.OperatorSubscribeOn$1.call(SourceFile:94)
     at rx.internal.schedulers.ScheduledAction.run(SourceFile:55)
     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
     at java.lang.Thread.run(Thread.java:818)
  </code></pre>
  
  <p>I am not able to figure out cause for this crash.</p>
  
  <p>I am not downloading images or creating bitmaps from inputstream, the log above gives idea that it is going out of memory while reading the certificate file.</p>