Multiple enqueue in retrofit causing out of memory error?

点点圈 提交于 2021-01-27 13:01:39

问题


Am doing my project using retrofit2. When my Call goes on failure i repeat same call again.Repeation of this call made my app to force close. When i look on log i got error log, which is given below. I felt this is caused by multiple enqueue to same Call. So i did that before enqueus i called cancel. But its not working. getting same force close.

FATAL EXCEPTION: main
Process: com.SocialMob, PID: 27846
java.lang.OutOfMemoryError: pthread_create (stack size 16384 bytes) failed: Try again
at java.lang.VMThread.create(Native Method)
at java.lang.Thread.start(Thread.java:1029)
at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:920)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1338)
at okhttp3.Dispatcher.enqueue(Dispatcher.java:112)
at okhttp3.RealCall.enqueue(RealCall.java:78)
at okhttp3.RealCall.enqueue(RealCall.java:70)
at retrofit2.OkHttpCall.enqueue(OkHttpCall.java:104)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall.enqueue(ExecutorCallAdapterFactory.java:58)
at com.SocialMob.Activities.SplashActivity.VersionCheck(SplashActivity.java:184)
at com.SocialMob.Activities.SplashActivity.access$500(SplashActivity.java:38)
at com.SocialMob.Activities.SplashActivity$1.onFailure(SplashActivity.java:177)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$2.run(ExecutorCallAdapterFactory.java:75)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)

Thanks in advance.


回答1:


You should avoid that approach, as it would make it a recursive call. Instead you should check the cause in the failure function first and then retry. Also fix the number of retry times.




回答2:


I am using Retrofit 2.0.2, and i have this tag in my manifest file:

android:largeHeap="true"

I am retrying on failure like this:

@Override
public void onFailure(Call<AudioResponse> call, Throwable error) {
    loading.setVisibility(View.GONE);
    if (mAdapter.getItemCount() == 0) {
        SetErrorContent();
    }
    Log.e("Error", error.getMessage() + "");

    call.cancel();
    call.clone().enqueue(this);
}

It is not crashing.Give it a try.



来源:https://stackoverflow.com/questions/37155783/multiple-enqueue-in-retrofit-causing-out-of-memory-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!