Crash when selecting a lot of cells in UICollectionView

Hey,

I am implementing a "Select All" functionality and experiencing a crash because of running out of memory when having a lot of cells.

Calling .selectItem(at:animated:scrollPosition:) on 10k cells need 1.5GB and 20k needs 7GB (crashes on a real device). After selection is completed, memory goes down to normal levels.

This broken both on iOS 18.5 and 26.5.

Minimal example: https://github.com/martonfarago/collectionViewMemoryTest

Is this a know issue? Is there another, maybe more efficient way of selecting all cells?

M

Hello, @interferenc!

Thank you for the detailed post. The numbers are very helpful.


 On the memory spike:
The scaling of 4-5 times the memory increase for 2 times the item count is definitely something worth looking at.

Are you able to file a bug report with Feedback Assistant and attach this sample project you provided?

Once complete, reply with the Feedback number so I can make sure this report is routed to the relevant engineering team.

As a workaround, rather than calling selectItem(at:animated:scrollPosition:) for every index path, maintain a Set<IndexPath> or an isAllSelected: Bool flag in your data source. Then in cellForItemAt, apply the visual selected state manually.

This avoids UICollectionView's internal selection machinery for 10k-20k of items at once, since it appears that it might not be designed to support that volume.

Creating a Feedback report will create direct dialog with the engineering team directly and they can even respond to you there. I'm curious to investigate this further with that team.

Thank you. I hope this helps.

 Travis

Hey Travis,

Reported here: https://feedbackassistant.apple.com/feedback/23525146

Thanks for the suggestions.

Thank you for filing!

I have made sure the report is in the right spot.

Updates will be provided to you through Feedback Assistant. There, you can track if the report is still being investigated, has a potential identified fix, or has been resolved in another way.

For more details on Feedback Status, please see “Understanding the Status of Your Feedback” linked here: https://developer.apple.com/bug-reporting/status

 Travis

Crash when selecting a lot of cells in UICollectionView
 
 
Q