Scrolling gallery in android, freeing up memory

So, I currently have a recycler view with a gridlayoutmanager that through the listener loads more bitmaps asynchronously. The problem is that when I scroll too far down, the program crashes due to the fact that ArrayList contains 1000+ bitmaps.

I tried to compress bitmaps using inSampleSize of 8 and load from thumbnails, so I assume this problem occurs in an array containing so many bitmaps.

My question is: is there any way, say, after 200 bitmaps start removing them from the array without violating the scroll system? After deleting them, how would I place the cursor to start getting bitmap images again? I can add a function that, after calling 200 bitmaps, but I need some tips for its implementation.

I think this is a very code-independent question, but if you need any code, you can see this repository .

Thank.

+4
source share

Source: https://habr.com/ru/post/1689762/


All Articles