I have a feed when clicking on item go to details, during it FeedFragment is detached and DetailsFragment pushed. When going back we're checking if an adapter is not null.
if (adapter == null) {
adapter = createAdapter();
}
if (recyclerView.getAdapter() == null) {
recyclerView.setAdapter(adapter);
}
The problem is when reusing adapter every time going to details and going back the amount of ViewHolders is doubled. And it can go on until it will freeze the app and OOM happens.
The question is why is this happening? Shouldn't adapter be detached from recyclerView and all items should be recycled?
P.S. this problem doesn't occur when creating new adapter when going back.