calling deleteRowsAtIndexPaths:withRowAnimation: or insertRowsAtIndexPaths:withRowAnimation: UITableView causes memory leak in iOS 7.0

Originator:joachim.schuster
Number:rdar://15085064 Date Originated:
Status:Closed Resolved:iOS 7.0.3
Product:iOS SDK Product Version:7.0
Classification: Reproducible:Always
 
Edit: Added a Sample Project. Details at the bottom of this description.

Summary:
The tableView(cells) receives to much retains in the process of animated insertion or deletion.
This causes the tableView (and its cells) to stay alive after the containing ViewController gets deallocated.

Steps to Reproduce:
1. Create a basic project with ViewController in a NavigationController.
2. Add a TableViewController which gets pushed.
3. in this TableViewController add a custom TableView with some custom TableViewCells and a deleteRowsAtIndexPaths:withRowAnimation: 
4. Set a breakpoint in the dealloc method of the CustomTableView and the CustomTableViewCell.
5. Run it an watch the CustomTableView and CustomTableViewCells gets deallocated if deleteRowsAtIndexPaths:withRowAnimation: was NOT called and popped from ViewController stack.
6. Do the same after a deleteRowsAtIndexPaths:withRowAnimation: on the tableView and you will see the CustomTableView and the CustomTableViewCells does not get removed.

Expected Results:
balanced retain and release count after the animation of the insertion / deletion of Cells.

Actual Results:
after the animation the retain count is to high, so the tableView will not get released.

Version:
iOS 7.0

Notes:
Somebody provided a kind of workaround as a answer in that stack overflow article: http://stackoverflow.com/questions/18919870/ios-7-0-and-arc-uitableview-never-deallocated-after-rows-animation

Another issue on stack overflow with the same problem:
http://stackoverflow.com/questions/18903234/updating-a-uitable-inside-didselectrowatindexpath-causes-leak-in-ios7-but-not-i

EDIT:
Added a Sample Project on github:
https://github.com/jschuster/RadarSamples/tree/master/TableViewCellAnimationBug

Open the Project in Xcode 5
Open the Classes CustomTableView and CustomTableViewCell and set a breakpoint in dealloc.

Run the App in iOS 7.0 environment.
 - tap "Show me the TableView" button and navigate back directly.
    -> dealloc will be called.
 - tab "Show me the TableView" button
    - delete a cell (swipe or edit) -> deletion of the cell is animated. See TableViewController:tableView:commitEditingStyle:forRowAtIndexPath:
    - navigate back
    -> dealloc will not be called.
 
 Run the App in iOS 6.x environment will release all objects as expected, no memory leak.

Comments

Good news! Apple has fixed this bug as of iOS 7.0.3 (released today, Oct 22 2013).

By smileyborg at Oct. 22, 2013, 11:45 p.m. (reply...)

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!