diff --git a/AsyncDisplayKit/ASDisplayNode.mm b/AsyncDisplayKit/ASDisplayNode.mm index 705a589da0..202cbae8c2 100644 --- a/AsyncDisplayKit/ASDisplayNode.mm +++ b/AsyncDisplayKit/ASDisplayNode.mm @@ -457,17 +457,6 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c) - (void)_scheduleIvarsForMainDeallocation { - /** - * UIKit components must be deallocated on the main thread. We use this shared - * run loop queue to gradually deallocate them across many turns of the main run loop. - */ - static ASRunLoopQueue *queue; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - queue = [[ASRunLoopQueue alloc] initWithRunLoop:CFRunLoopGetMain() andHandler:nil]; - queue.batchSize = 10; - }); - NSValue *ivarsObj = [[self class] _ivarsThatMayNeedMainDeallocation]; // Unwrap the ivar array @@ -482,7 +471,7 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c) id value = object_getIvar(self, ivar); if (ASClassRequiresMainThreadDeallocation(object_getClass(value))) { LOG(@"Trampolining ivar '%s' value %@ for main deallocation.", ivar_getName(ivar), value); - [queue enqueue:value]; + ASPerformMainThreadDeallocation(value); } else { LOG(@"Not trampolining ivar '%s' value %@.", ivar_getName(ivar), value); } diff --git a/AsyncDisplayKit/ASDisplayNodeExtras.h b/AsyncDisplayKit/ASDisplayNodeExtras.h index f7e0a61ba0..e7cbf30192 100644 --- a/AsyncDisplayKit/ASDisplayNodeExtras.h +++ b/AsyncDisplayKit/ASDisplayNodeExtras.h @@ -14,6 +14,9 @@ #import #import +/// For deallocation of objects on the main thread across multiple run loops. +extern void ASPerformMainThreadDeallocation(_Nullable id object); + // Because inline methods can't be extern'd and need to be part of the translation unit of code // that compiles with them to actually inline, we both declare and define these in the header. ASDISPLAYNODE_INLINE BOOL ASInterfaceStateIncludesVisible(ASInterfaceState interfaceState) diff --git a/AsyncDisplayKit/ASDisplayNodeExtras.mm b/AsyncDisplayKit/ASDisplayNodeExtras.mm index bdf1fc79d6..97b22578b7 100644 --- a/AsyncDisplayKit/ASDisplayNodeExtras.mm +++ b/AsyncDisplayKit/ASDisplayNodeExtras.mm @@ -13,6 +13,24 @@ #import "ASDisplayNode+FrameworkPrivate.h" #import +#import "ASRunLoopQueue.h" + +extern void ASPerformMainThreadDeallocation(_Nullable id object) +{ + /** + * UIKit components must be deallocated on the main thread. We use this shared + * run loop queue to gradually deallocate them across many turns of the main run loop. + */ + static ASRunLoopQueue *queue; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + queue = [[ASRunLoopQueue alloc] initWithRunLoop:CFRunLoopGetMain() andHandler:nil]; + queue.batchSize = 10; + }); + if (object != nil) { + [queue enqueue:object]; + } +} extern ASInterfaceState ASInterfaceStateForDisplayNode(ASDisplayNode *displayNode, UIWindow *window) {