UITableView retaining WAY too many UITableViewCells

Originator:ubuermey
Number:rdar://15960119 Date Originated:2014/01/31
Status:open Resolved:
Product:iOS SDK Product Version:
Classification:important Reproducible:always
 
Summary:

Please see https://devforums.apple.com/message/937435 for a detailed description.

In short: If I return custom cells from cellForRowAtIndexPath in an ARC project, the tableView retains as many cells as the dataSource has rows, as opposed to only the number of cells necessary to display the tableView.

This is NOT a re-use issue; cells are being reused (via dequeue ...), but from a pool of, say, 50 if that's the number of rows the dataSource, not of around 12 (the number of visible rows).

As soon as the tableView is deallocated, all cells are deallocated as well, so apparently there is no strong reference to the cells dangling somewhere in my own code.

The reuseIdentifier is set correctly in IB as well as in the source code using a static NSString*

Steps to Reproduce:

1. create NIB for a UITableViewCell with two UILabels as subviews, activate autoLayout, use constraints to let the UILabels define the row height

2. in cellForRow ... try to dequeue, and if that fails, create cell "the old way" via loadNib (but the registerNib approach has the same effect)

3. in the custom UITableViewCell subclass, create a static int that is incremented on awakeFromNib & decremented in dealloc

4. log shows that the tableView allocates & retains as many cells as the dataSource has rows - that is, when scrolling down to the bottom, no dequeueing of used cells occurs until all rows have been displayed at least once

5. when scrolling up again, cells are being reused, no more awakeFromNib

6. when scrolling up and down again, no awakes / deallocs

7. when deallocating the tableView - e.g., by removeFromSuperview in viewWillDisappear and nil-ing the property - all cells get deallocated at once

I'm using ARC in my project.

Expected Results:

tableView retains roughly as many cells as are displayed at the same time (in my case ca. 12)

Actual Results:

tableView retains cells for each and every row in dataSource, up to several hundreds

Version:

iOS SDK 7.0.3 / 7.1 b4


Notes:

This reminds me of the issue reportedly fixed in 7.0.3 concerning rowAnimations in a tableView ... according to Instruments, the layers of my UILabels (subviews of the cells) are allocated in some animation as well, maybe the cells are over retained in that context.

Configuration:

Xcode 5.0.2 / 5.1 b4

Comments


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!