From daa12a867eaa06e9dbcd9d4c085881b18f3e3c1d Mon Sep 17 00:00:00 2001 From: Garrett Moon Date: Wed, 11 Jan 2017 17:00:27 -0800 Subject: [PATCH] Need an autorelease pool (#2890) --- AsyncDisplayKit/ASRunLoopQueue.mm | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/AsyncDisplayKit/ASRunLoopQueue.mm b/AsyncDisplayKit/ASRunLoopQueue.mm index 7e50424a59..076b6cc56a 100644 --- a/AsyncDisplayKit/ASRunLoopQueue.mm +++ b/AsyncDisplayKit/ASRunLoopQueue.mm @@ -60,19 +60,21 @@ static void runLoopSourceCallback(void *info) { // 100ms timer. No resources are wasted in between, as the thread sleeps, and each check is fast. // This time is fast enough for most use cases without excessive churn. CFRunLoopTimerRef timer = CFRunLoopTimerCreateWithHandler(NULL, -1, 0.1, 0, 0, ^(CFRunLoopTimerRef timer) { + @autoreleasepool { #if ASRunLoopQueueLoggingEnabled - NSLog(@"ASDeallocQueue Processing: %d objects destroyed", weakSelf->_queue.size()); + NSLog(@"ASDeallocQueue Processing: %d objects destroyed", weakSelf->_queue.size()); #endif - weakSelf->_queueLock.lock(); - std::deque currentQueue = weakSelf->_queue; - if (currentQueue.size() == 0) { + weakSelf->_queueLock.lock(); + std::deque currentQueue = weakSelf->_queue; + if (currentQueue.size() == 0) { + weakSelf->_queueLock.unlock(); + return; + } + // Sometimes we release 10,000 objects at a time. Don't hold the lock while releasing. + weakSelf->_queue = std::deque(); weakSelf->_queueLock.unlock(); - return; + currentQueue.clear(); } - // Sometimes we release 10,000 objects at a time. Don't hold the lock while releasing. - weakSelf->_queue = std::deque(); - weakSelf->_queueLock.unlock(); - currentQueue.clear(); }); CFRunLoopRef runloop = CFRunLoopGetCurrent();