Skip to content

Commit e703255

Browse files
authored
Only clear ASCollectionView's data during deallocation (TextureGroup#1154)
This is a follow up on TextureGroup#1136. Our experiment results show that clearing data frequently is the cause of our #1 crash. @maicki and I believe that this is because if the collection view is being used, silently clearing its data without notifying the backing UICollectionView can put it out-of-sync and causes mayhem next time the collection view processes a batch update. If you look at the stack trace closely, you'll notice that the crash doesn't occur on the same run loop that clearData is called. This made it extremely tricky to investigate and identify the root cause. Another interesting question would be whether or not we want to clear the data during deallocation at all, since the data will be cleared out soon anyway.
1 parent 9588692 commit e703255

File tree

5 files changed

+6
-4
lines changed

5 files changed

+6
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
- Optimize layout process by removing `ASRectMap`. [Adlai Holler](https://github.com/Adlai-Holler)
5252
- Remove necessity to use view to access rangeController in ASTableNode, ASCollectionNode. [Michael Schneider](https://github.com/maicki)
5353
- Remove display node's reliance on shared_ptr. [Adlai Holler](https://github.com/Adlai-Holler)
54+
- [ASCollectionView] Fix a crash that is caused by clearing a collection view's data while it's still being used. [Huy Nguyen](https://github.com/nguyenhuy) [#1154](https://github.com/TextureGroup/Texture/pull/1154)
5455
- Clean up timing of layout tree flattening/ copying of unflattened tree for Weaver. [Michael Zuccarino](https://github.com/mikezucc) [#1157](https://github.com/TextureGroup/Texture/pull/1157)
5556

5657
## 2.7

Schemas/configuration.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"exp_network_image_queue",
2222
"exp_dealloc_queue_v2",
2323
"exp_collection_teardown",
24-
"exp_framesetter_cache"
24+
"exp_framesetter_cache",
25+
"exp_clear_data_during_deallocation"
2526
]
2627
}
2728
}

Source/ASCollectionView.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ - (void)_asyncDelegateOrDataSourceDidChange
577577
{
578578
ASDisplayNodeAssertMainThread();
579579

580-
if (_asyncDataSource == nil && _asyncDelegate == nil && !ASActivateExperimentalFeature(ASExperimentalSkipClearData)) {
580+
if (_asyncDataSource == nil && _asyncDelegate == nil && _isDeallocating && ASActivateExperimentalFeature(ASExperimentalClearDataDuringDeallocation)) {
581581
[_dataController clearData];
582582
}
583583
}

Source/ASExperimentalFeatures.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ typedef NS_OPTIONS(NSUInteger, ASExperimentalFeatures) {
2323
ASExperimentalNetworkImageQueue = 1 << 5, // exp_network_image_queue
2424
ASExperimentalCollectionTeardown = 1 << 6, // exp_collection_teardown
2525
ASExperimentalFramesetterCache = 1 << 7, // exp_framesetter_cache
26-
ASExperimentalSkipClearData = 1 << 8, // exp_skip_clear_data
26+
ASExperimentalClearDataDuringDeallocation = 1 << 8, // exp_clear_data_during_deallocation
2727
ASExperimentalFeatureAll = 0xFFFFFFFF
2828
};
2929

Source/ASExperimentalFeatures.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
@"exp_dealloc_queue_v2",
2222
@"exp_collection_teardown",
2323
@"exp_framesetter_cache",
24-
@"exp_skip_clear_data"]));
24+
@"exp_clear_data_during_deallocation"]));
2525

2626
if (flags == ASExperimentalFeatureAll) {
2727
return allNames;

0 commit comments

Comments
 (0)