17

I am facing this weird crash on prod on recycler view while recycling the items and I am not able to reproduce this crash also.

  Fatal Exception: java.lang.IllegalStateException: Already in the pool!
   at androidx.core.util.Pools$SimplePool.release(Pools.java:117)
   at androidx.recyclerview.widget.AdapterHelper.recycleUpdateOp(AdapterHelper.java:743)
   at androidx.recyclerview.widget.AdapterHelper.recycleUpdateOpsAndClearList(AdapterHelper.java:750)
   at androidx.recyclerview.widget.AdapterHelper.consumePostponedUpdates(AdapterHelper.java:123)
   at androidx.recyclerview.widget.AdapterHelper.consumeUpdatesInOnePass(AdapterHelper.java:557)
   at androidx.recyclerview.widget.RecyclerView.processAdapterUpdatesAndSetAnimationFlags(RecyclerView.java:3585)
   at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:3829)
   at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3639)
   at androidx.recyclerview.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1877)
   at androidx.recyclerview.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5044)
   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1092)
   at android.view.Choreographer.doCallbacks(Choreographer.java:893)
   at android.view.Choreographer.doFrame(Choreographer.java:809)
   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1078)
   at android.os.Handler.handleCallback(Handler.java:891)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:207)
   at android.app.ActivityThread.main(ActivityThread.java:7539)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)
17
  • so no stacktraces related to your app code?
    – kaushalyap
    Commented Aug 23, 2019 at 3:40
  • @user158 no stacktraces related to app Commented Aug 23, 2019 at 5:08
  • If you on latest RV version move back to an older version,otherwise move to a newer version.
    – kaushalyap
    Commented Aug 23, 2019 at 5:15
  • @user158 this is the newer version of androidX Commented Aug 23, 2019 at 10:33
  • what is the RV version?
    – kaushalyap
    Commented Aug 23, 2019 at 10:35

3 Answers 3

5

The exception is thrown when two different threads are trying to reach your recycle view instance to update it.

Let's clarify it. assume Thread A goes to update your recycle view Then next Thread B tries to do the same as A. as a result, Exception thrown, says A already in the pool (Already in the pool!)

after some researches, to find the solution, I found these approaches

Synchronized Methods

synchronized(recycleview)
{

}

Pools.SynchronizedPool

using androidx.core.util.Pools.SynchronizedPool<T> instead of androidx.core.util.Pools.SimplePool

both approaches try to synchronize accessing critical sections to avoid throwing exceptions.

0

You are updating the recyclerView while it is computing. You should do something like this:

if (recyclerView != null) {
            recyclerView.post(new Runnable() {
                @Override
                public void run() {
                    notifyDataSetChange(); //whatever you use, insert, remove, itemChanged etc...
                }
            });
        }
0

The source of problem for my case was

thisRecycler?.getRecycledViewPool()?.clear() called too frequently that synchronous operations weren't performed on this line

It was introduced as alternative to

notifyItemRangeRemoved(0, previousContentSize)
.
.
notifyItemRangeInserted(0, newRecyclerContent.size - 1)

Now the code is stable with usage of

notifyItemRangeRemoved(0, previousContentSize)
.
.
notifyDataSetChanged()  

Not the answer you're looking for? Browse other questions tagged or ask your own question.