Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

[ASDisplayNode] Fix assertion on cell deallocation (work around UIKit inconsistency - visibleCells != visibleIndexPaths) #1593

Merged
merged 3 commits into from
Apr 26, 2016
Merged

Conversation

maicki
Copy link
Contributor

@maicki maicki commented Apr 26, 2016

Should fix: #1512 and #1569

Further information:

  • We mark every node as visible in the ASRangeController which NSIndexPath is returned from visibleNodeIndexPathsForRangeController:
  • In visibleNodeIndexPathsForRangeController: we get the visible index path's via a call to UITableView's "indexPathsForVisibleRows" method.
  • Unfortunately in this case we cannot use indexPathsForVisibleRows to get all the visible index paths as apparently in a grouped UITableView it would return index paths for cells that are just a bit over the edge of the visible area.
  • But this edge cells will never get a call for -tableView:cellForRowAtIndexPath:, but we will mark them as visible in the range controller
  • In tableView:cellForRowAtIndexPath: we call -configureContentView:forCellNode
  • Because we never get a -configureContentView:forCellNode call for the edge cells, the _ASDisplayView of the nodes will never be added to the window and get a willMoveToWindow and didMoveToWindow call and it's never get's added to the window for now and so the node is NOT marked as "in the hirarchy"
  • If the deallocation of the views are happening without the UITableView ever scrolled, the cells don't get a call to __exitHierarchy as they were never added to the window and stay in the interface state "visible" and an exception will be raised within the dealloc method of the ASDisplayNode

Further information:
- We mark every node as visible in the ASRangeController which NSIndexPath is returned from visibleNodeIndexPathsForRangeController:
- In visibleNodeIndexPathsForRangeController: we get the visible index path's via a call to UITableView's "indexPathsForVisibleRows" method.
- Unfortunately in this case we cannot use indexPathsForVisibleRows to get all the visible index paths as apparently in a grouped UITableView it would return index paths for cells that are just a bit over the edge of the visible area.
- But this edge cells will never get a call for -tableView:cellForRowAtIndexPath:, but we will mark them as visible in the range controller
- In tableView:cellForRowAtIndexPath: we call -configureContentView:forCellNode
- Because we never get a -configureContentView:forCellNode call for the edge cells, the _ASDisplayView of the nodes will never be added to the window and get a willMoveToWindow and didMoveToWindow call and it's never get's added to the window for now and so the node is NOT marked as "in the hirarchy"
- If the deallocation of the views are happening without the UITableView ever scrolled, the cells don't get a call to __exitHierarchy as they were never added to the window and stay in the interface state "visible" and an exception will be raised within the dealloc method of the ASDisplayNode
We move from block based enumeration for the array to fast enumeration as from a benchmark perspective this is faster. For the dictionary we stay with block based enumeration as looking up the value for the key in e.g. fast enumeration would be slower as using the block based API where we get the key and value for passed in
[_completedNodes enumerateKeysAndObjectsUsingBlock:^(NSString *kind, NSMutableArray *nodes, BOOL *stop) {
[nodes enumerateObjectsUsingBlock:^(NSMutableArray *section, NSUInteger sectionIndex, BOOL *stop) {
[section enumerateObjectsUsingBlock:^(ASCellNode *node, NSUInteger rowIndex, BOOL *stop) {
[_completedNodes enumerateKeysAndObjectsUsingBlock:^(NSString *kind, NSMutableArray *sections, BOOL *stop) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eanagel Hi Ethan, do we still need to remove all the layer / views from the node in here? Why did we added that in the first place?

cc @appleguy

@ghost ghost added the CLA Signed label Apr 26, 2016
@appleguy appleguy merged commit f7985d2 into facebookarchive:master Apr 26, 2016
@appleguy appleguy changed the title [ASDisplayNode] Fix assertion on cell deallocation due visibility not being cleared [ASDisplayNode] Fix assertion on cell deallocation (work around Apple inconsistency - visibleCells != visibleIndexPaths) Apr 26, 2016
@appleguy appleguy changed the title [ASDisplayNode] Fix assertion on cell deallocation (work around Apple inconsistency - visibleCells != visibleIndexPaths) [ASDisplayNode] Fix assertion on cell deallocation (work around UIKit inconsistency - visibleCells != visibleIndexPaths) Apr 26, 2016
@appleguy appleguy added this to the 1.9.8 milestone Apr 26, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ASCellNode] Assertion on cell deallocation due visibility not being cleared
2 participants