0

I have a simple recyclerView. When scrolling, items are getting fetched from a Room Database and being added to the recycler's list.

I wondering how many items can be added before throws OOM?

Is there any way to control this? Example: In instagram's search section you cant scroll down forever right?

aminography
  • 21,986
  • 13
  • 70
  • 74
Nick
  • 2,818
  • 5
  • 42
  • 60
  • It would add rows forever until you reach the limit of ArrayList :) Please read concept of recycler view. – Pankaj Kumar Sep 09 '18 at 02:00
  • @PankajKumar And when i will reach ArrayList's limit? After scrolling for a while, OOM is inevitable? – Nick Sep 09 '18 at 09:43
  • No. In that case also you will not have OOM issue as RecyclerView reuses cells you will never have this issue. BUT your other logic may cause OOM which I think you know such things. – Pankaj Kumar Sep 09 '18 at 15:47

1 Answers1

1

RecyclerView creates limited number of views, then populate them by your data. So, there is no limits to show the items until some problems happened like reaching the Integer MAX_VALUE (because of containing list position), etc...

aminography
  • 21,986
  • 13
  • 70
  • 74
  • Irrelevant answer. Iam asking about the ArrayList inside RecyclerView. – Nick Sep 09 '18 at 09:41
  • Since there is an array in ArrayList data structure and the positioning of array is done by integer values (at most about 2 billions), there is a limit on ArrayList size and subsequently RecyclerView which is uses ArrayList. However, no mobile device exists with memory that supports about 2 billions data objects to show in RecyclerView. – aminography Sep 09 '18 at 09:53
  • So if i scroll for a very long time, app will throw OOM? or can i handle this somehow? – Nick Sep 09 '18 at 09:54
  • By pagination you can handle large list loading. So there limited number of items exist in memory at the same time. Look at https://developer.android.com/topic/libraries/architecture/paging. I think it's helpful. – aminography Sep 09 '18 at 10:00
  • Yeah i know but if i keep scrolling even with pagination, i will in some point get close to Array's limit. – Nick Sep 09 '18 at 10:03
  • If you would be able to scroll items with speed of 100 items per second, this work takes about 248 days. So, you can't reach this limitation dude :) – aminography Sep 09 '18 at 10:10