小编Ker*_*dex的帖子

我是否需要在 DispatchQueue.main.async 中使用 autoreleasepool 块

在 Xcode 8.2.1 中为 iOS 应用程序使用 swift 3。

我知道在新线程上分派一些处理时我需要一个 autoreleasepool 块。但是在主线程上调度回时是否需要它?

假设我们在主线程上并执行以下操作:

    DispatchQueue.global(qos: .background).async {
        autoreleasepool {
            //***** do something in the background
        } // autoreleasepool

        DispatchQueue.main.async {
            //***** do something on the main thread when background job is done
            //***** does this something need to be enclosed in an autoreleasepool block ?
        } // DispatchQueue.main.async

    } // DispatchQueue.global
Run Code Online (Sandbox Code Playgroud)

multithreading ios swift

5
推荐指数
1
解决办法
1812
查看次数

标签 统计

ios ×1

multithreading ×1

swift ×1