From 93312f26e67324554d5c6c6f81907c0886d03686 Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Mon, 1 Oct 2018 16:59:41 -0700 Subject: [PATCH] Only clear ASCollectionView's data during deallocation This is a follow up on #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. --- Source/ASCollectionView.mm | 2 +- Source/ASExperimentalFeatures.h | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/ASCollectionView.mm b/Source/ASCollectionView.mm index 94406b0ee..0c36204a0 100644 --- a/Source/ASCollectionView.mm +++ b/Source/ASCollectionView.mm @@ -577,7 +577,7 @@ - (void)_asyncDelegateOrDataSourceDidChange { ASDisplayNodeAssertMainThread(); - if (_asyncDataSource == nil && _asyncDelegate == nil && !ASActivateExperimentalFeature(ASExperimentalSkipClearData)) { + if (_asyncDataSource == nil && _asyncDelegate == nil && _isDeallocating && ASActivateExperimentalFeature(ASExperimentalClearDataDuringDeallocation)) { [_dataController clearData]; } } diff --git a/Source/ASExperimentalFeatures.h b/Source/ASExperimentalFeatures.h index 2af937d66..dc833e437 100644 --- a/Source/ASExperimentalFeatures.h +++ b/Source/ASExperimentalFeatures.h @@ -21,9 +21,10 @@ typedef NS_OPTIONS(NSUInteger, ASExperimentalFeatures) { ASExperimentalUnfairLock = 1 << 3, // exp_unfair_lock ASExperimentalLayerDefaults = 1 << 4, // exp_infer_layer_defaults ASExperimentalNetworkImageQueue = 1 << 5, // exp_network_image_queue - ASExperimentalCollectionTeardown = 1 << 6, // exp_collection_teardown - ASExperimentalFramesetterCache = 1 << 7, // exp_framesetter_cache - ASExperimentalSkipClearData = 1 << 8, // exp_skip_clear_data + ASExperimentalDeallocQueue = 1 << 6, // exp_dealloc_queue_v2 + ASExperimentalCollectionTeardown = 1 << 7, // exp_collection_teardown + ASExperimentalFramesetterCache = 1 << 8, // exp_framesetter_cache + ASExperimentalClearDataDuringDeallocation = 1 << 9, // exp_clear_data_during_deallocation ASExperimentalFeatureAll = 0xFFFFFFFF };