NSBlockOperations导致内存泄漏,导致deinit永远不会被调用[swift]

时间:2016-09-06 07:17:17

标签: ios swift nsfetchedresultscontroller nsoperation nsblockoperation

var blockOperations = [NSBlockOperation]()
func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {

    if type == .Insert {
        blockOperations.append(NSBlockOperation(block: {
            self.collectionView?.insertItemsAtIndexPaths([newIndexPath!])

        }))
    }
}
    func controllerDidChangeContent(controller: NSFetchedResultsController) {
    collectionView?.performBatchUpdates({
        for operation in self.blockOperations {
            operation.start()

        }
        }, completion: { (completed) in
           print("completed")
    })

}

这是我将消息插入我的集合视图的代码。

我需要块操作,以便在消息被延迟时可以插入块事件中。

问题是我每次都忽略了viewController print("completed")重复项。这意味着我有内存泄漏。

除非我删除块操作,否则永远不会调用deinit,当我离开viewController时如何释放阻止操作?

0 个答案:

没有答案