UICollectionView doesn't properly dequeue cells when UI Automation is running with Instruments, causing a memory leak

Originator:romefimov
Number:rdar://17732716 Date Originated:18-Jul-2014 03:37 PM
Status:Open Resolved:
Product:iOS Product Version:7.1.2, 8.0
Classification:No Rank Reproducible:Always
 
Summary:
For example, UICollectionView has 6 unique identifiers all registered for a UICollectionViewCell and it has exactly 6 cells, each has a unique identifier. 

When you're running an automation test, the collection view will not properly dequeue cells and would create new instances more than required. Eventually, there might be thousands of cell instances - all living in memory and not being deallocated.

Steps to Reproduce:
1. Compile and run CollectionViewTest on an iPhone running iOS 7
2. Start UI Automation + Allocations test with Instruments using a monkey test script (attached in the zip).
3. Verify that the number of objects is more than 6. <----- BUG
4. Run the test again, but now disable the UI Automation test. 
5. Scroll the collection view up and down few times.
6. There will be exactly 6 instances.

Expected Results:
There are 6 cells and exactly 6 identifiers. Instruments should show that there are 6 objects allocated.

Actual Results:
UICollectionView keeps creating new cells and not reusing the existing cells. Moreover, if you run this test for a long time (a few hours) the numbers of cells will grow exponentially with every scroll and the old cells won't be deallocated which would lead to an out of memory crash.

Version:
iOS 7.1.2

Notes:


Configuration:
iPhone 5s 64GB Verizon, Wi-Fi

Comments

iOS 8.0 still has this issue

This hasn't been resolved with iOS 8.0.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!