I implemented a method that reads the user's contacts and puts them in the ArrayList<Friend> list and it turns out that there are 300 contacts in my address book and in order to fill the array, the method has to create 300 objects and put them into a list

and I get these lines in the log:

07-27 16: 20: 39.663 18588-18698 / com.fittingroom.newtimezone I / art: Explicit concurrent mark sweep GC freed 7741 (518KB) AllocSpace objects, 2 (40KB) LOS objects, 12% free, 26MB / 30MB, paused 1.294ms total 55.011ms 07-27 16: 20: 40.952 18588-18698 / com.fittingroom.newtimezone I / art: Explicit concurrent mark sweep GC freed 18304 (700KB) AllocSpace objects, 0 (0B) LOS objects, 12% free, 27MB / 31MB; , 12% free, 27MB / 31MB, paused 1.332ms total 52.736ms 07-27 16: 20: 43.519 18588-18698 / com.fittingroom.newtimezone I / art: Explicit concurrent mark sweep GC freed 20440 (782KB) AllocSpace objects, 0 (0B) LOS objects, 12% free, 27MB / 31MB, paused 1.587ms total 53.310ms 07-27 16: 20: 44.782 18588-18698 / com.fittingroom.newtimezone I / art: Explicit concurrent mark sweep GC freed 20851 (799KB ) AllocSpace objects, 0 (0B) LOS objects, 12% f ree, 27MB / 31MB, paused 1.539ms total 53.030ms

I read and understood that this collector collects what is no longer needed in the process of creating these objects ...

The question is, what if the user has 1000 contacts?

Will the application crash in this case?

And how to load the entire list at once? maybe it is worth loading it in RecyclerView in parts?

Tell me how right?

  • As far as I understand RecyclerView will not load all the items at once, it loads new items as it rolls. - Kirill Stoianov
  • one
    @KirillStoianov Yes, but he will download them from the ArrayList that contains all these contacts ... The question is, do you need to take all the contacts from the phone book right away or load them in parts? - Aleksey Timoshchenko
  • You can add LIMIT to your query, say 100, and as you scroll (endless list), load the next 100 contacts - Android Android
  • I tried to load about 1000 contacts with all fields into one list for ListView and the application did not fall. - Kirill Stoianov
  • The wise said: divide and conquer. This is true to this day. Even on infinite memory with infinite performance. - DimXenon

2 answers 2

ArrayList can accept Integer.MAX_VALUE elements. on Earth I do not think that all 2 147 483 647 have telephones. so the answer is NO, not overflow

And how to load the entire list at once? maybe it is worth loading it in> RecyclerView in parts? depends on speed. if the speed of reading with memory allows, then do

  • That was the essence of my question)) Thank you! - Aleksey Timoshchenko pm

There is no point in loading information into the RecyclerView information. he himself takes exactly as much from the adapter as he needs the elements to display + 2 additional elements .. i.e. the number of elements in RecyclerView it regulates itself communicating with the adapter and it depends on the screen size.

  • one
    That question is not how many elements will fit into RecyclerView, but does it make sense to fill the adapter for it with all the contacts at once? He still takes them in parts, does he need to ship him 10,000 contacts, if he will only take 10? - Aleksey Timoshchenko