So the answer might simply be memory related. But I wanted to ask to be sure...
I have an activity with some content and a horizontal recyclerview. The horizontal recyclerview shows max ~20 items which are all images. I use Glide to load those images and the scroll on the recyclerview is great, it's smooth and rarely lags. When you click on the image item in the recyclerview it opens the same activity (but with new data). This is where the problems start.
If I open multiple activities > 10 the recyclerview in each activity gets slower and slower and beings to lag more. Is there a memory leak somewhere? I thought at first that this would be expected as I'm creating a large number of activities but then I thought that it shouldn't matter because each activity should be calling onPause() and then onDestroy() if memory was a concern.
Does anyone know if this is expected behavior or if there really is a memory leak somewhere? Also the activity scrollview doesn't lag but the recyclerview will once a large number of activities are created.
No, this is not the expected behavior, and yes, definitely sounds like a memory leak. Unfortunately, there is no way for us to really help you with finding the memory leak without seeing more of your code. I would check if there is any reference of the previous activity inside the new activity, or any static references, or anything that would cause the previous activity to not get cleaned up.
Do you need to open the same activity but with a new instance of it? Do you want to keep the back stack behavior? If not, you should reuse the same activity but pass it a new Intent
to rebind the new data and make the activity singleTop
or singleTask
.