From 6d6e7bb5f39f9447882b82ec84186ce0116f3963 Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Tue, 13 Feb 2018 11:46:37 -0800 Subject: [PATCH 1/2] Avoid triggering main thread assertions in ASCollectionNode/ASTableNode dealloc --- Source/ASCollectionNode.mm | 9 +++++++-- Source/ASTableNode.mm | 9 +++++++-- Source/Base/ASAssert.h | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Source/ASCollectionNode.mm b/Source/ASCollectionNode.mm index 01669ca79..d0cc5f208 100644 --- a/Source/ASCollectionNode.mm +++ b/Source/ASCollectionNode.mm @@ -172,12 +172,17 @@ - (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionVi return self; } +#if ASDISPLAYNODE_ASSERTIONS_ENABLED - (void)dealloc { - if ([self isNodeLoaded]) { - ASDisplayNodeAssert(self.view.superview == nil, @"Node's view should be removed from hierarchy."); + if (self.nodeLoaded) { + __weak UIView *view = self.view; + ASPerformBlockOnMainThread(^{ + ASDisplayNodeCAssertNil(view.superview, @"Node's view should be removed from hierarchy."); + }); } } +#endif #pragma mark ASDisplayNode diff --git a/Source/ASTableNode.mm b/Source/ASTableNode.mm index 09e5eb9bd..c35f90a87 100644 --- a/Source/ASTableNode.mm +++ b/Source/ASTableNode.mm @@ -104,12 +104,17 @@ - (instancetype)init return [self initWithStyle:UITableViewStylePlain]; } +#if ASDISPLAYNODE_ASSERTIONS_ENABLED - (void)dealloc { - if ([self isNodeLoaded]) { - ASDisplayNodeAssert(self.view.superview == nil, @"Node's view should be removed from hierarchy."); + if (self.nodeLoaded) { + __weak UIView *view = self.view; + ASPerformBlockOnMainThread(^{ + ASDisplayNodeCAssertNil(view.superview, @"Node's view should be removed from hierarchy."); + }); } } +#endif #pragma mark ASDisplayNode diff --git a/Source/Base/ASAssert.h b/Source/Base/ASAssert.h index 336ac3d0e..b4521a61a 100644 --- a/Source/Base/ASAssert.h +++ b/Source/Base/ASAssert.h @@ -21,7 +21,7 @@ #import #import -#define ASDISPLAYNODE_ASSERTIONS_ENABLED (!defined(NS_BLOCK_ASSERTIONS)) +#define ASDISPLAYNODE_ASSERTIONS_ENABLED (!defined(NS_BLOCK_ASSERTIONS) || !NS_BLOCK_ASSERTIONS) /** * Note: In some cases it would be sufficient to do e.g.: From a100e5da5bae54c8359c3f74b75c05450978708e Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Tue, 13 Feb 2018 11:53:13 -0800 Subject: [PATCH 2/2] Put it back --- Source/Base/ASAssert.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Base/ASAssert.h b/Source/Base/ASAssert.h index b4521a61a..336ac3d0e 100644 --- a/Source/Base/ASAssert.h +++ b/Source/Base/ASAssert.h @@ -21,7 +21,7 @@ #import #import -#define ASDISPLAYNODE_ASSERTIONS_ENABLED (!defined(NS_BLOCK_ASSERTIONS) || !NS_BLOCK_ASSERTIONS) +#define ASDISPLAYNODE_ASSERTIONS_ENABLED (!defined(NS_BLOCK_ASSERTIONS)) /** * Note: In some cases it would be sufficient to do e.g.: