pusher / push-notifications-android

Android SDK for Pusher Beams
https://www.pusher.com/beams
MIT License
22 stars 22 forks source link

Single OkHttpClient in ReportingAPI #106

Open binzram opened 4 years ago

binzram commented 4 years ago

RecentlyOutOfMemoryError exceptions occurred when receiving high amount of PusherBeams notifications in our app.

Fatal Exception: java.lang.OutOfMemoryError: Could not allocate JNI Env
       at java.lang.Thread.nativeCreate(Thread.java)
       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.ConnectionPool.put(ConnectionPool.java:153)
       at okhttp3.OkHttpClient$1.put(OkHttpClient.java:167)
       ...
       at com.pusher.pushnotifications.api.PusherLibraryHeaderInterceptor.intercept(PusherLibraryHeaderInterceptor.kt:13)
       ...

According to this stackoverflow post each new okHttpClient has his own connection pool.

By instantiating only one instance of the client future request add up in the same connection pool and runs memory efficient.