From 6c2cfcf6c71666d27b455b3d7765c562f9185be8 Mon Sep 17 00:00:00 2001 From: Maxime Ollivier Date: Wed, 24 Jul 2024 14:11:59 -0700 Subject: [PATCH] clean up IGListExperimentKeepPointerToCollectionViewDataSource Summary: QE launched and reduced crashes, so lets clean up Differential Revision: D60184705 fbshipit-source-id: 574b0228e3efadf7bd3bd0677a4373a3b95888d1 --- Source/IGListDiffKit/IGListExperiments.h | 2 -- Source/IGListKit/Internal/IGListBatchUpdateTransaction.m | 9 ++++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Source/IGListDiffKit/IGListExperiments.h b/Source/IGListDiffKit/IGListExperiments.h index e0413bd7a..a85f2edea 100644 --- a/Source/IGListDiffKit/IGListExperiments.h +++ b/Source/IGListDiffKit/IGListExperiments.h @@ -20,8 +20,6 @@ typedef NS_OPTIONS (NSInteger, IGListExperiment) { IGListExperimentInvalidateLayoutForUpdates = 1 << 2, /// Throw NSInternalInconsistencyException during an update IGListExperimentThrowOnInconsistencyException = 1 << 3, - /// Test keeping a strong pointer to the collectionView.dataSource during a batch update to avoid a crash - IGListExperimentKeepPointerToCollectionViewDataSource = 1 << 4, }; /** diff --git a/Source/IGListKit/Internal/IGListBatchUpdateTransaction.m b/Source/IGListKit/Internal/IGListBatchUpdateTransaction.m index 14fd9da0d..51c56a15b 100644 --- a/Source/IGListKit/Internal/IGListBatchUpdateTransaction.m +++ b/Source/IGListKit/Internal/IGListBatchUpdateTransaction.m @@ -136,11 +136,10 @@ - (void)_didDiff:(IGListIndexSetResult *)diffResult onBackground:(BOOL)onBackgro [self.delegate listAdapterUpdater:self.updater didDiffWithResults:diffResult onBackgroundThread:onBackground]; @try { - // Experiment with keeping a pointer to the self.collectionView.dataSource, because we're seeing a crash where it could be missing. - const BOOL keepDataSource = IGListExperimentEnabled(self.config.experiments, IGListExperimentKeepPointerToCollectionViewDataSource); - id const collectionViewDataSource = keepDataSource ? self.collectionView.dataSource : nil; - - if (self.collectionView.dataSource == nil || (keepDataSource && collectionViewDataSource == nil)) { + // Keeping a pointer to self.collectionView.dataSource, because it can get deallocated before the UICollectionView and crash + id const collectionViewDataSource = self.collectionView.dataSource; + + if (collectionViewDataSource == nil) { // If the data source is nil, we should not call any collection view update. [self _bail]; } else if (diffResult.changeCount > 100 && self.config.allowsReloadingOnTooManyUpdates) {