What is the equivalent of @autoreleasepool in Swift?

隐身守侯 提交于 2019-12-03 06:26:25

问题


In Swift, I notice there is no @autoreleasepool{} construct, although Swift does use ARC. What is the proper way to manage an autoreleasepool in Swift, or has it been removed for some reason?


回答1:


This is explained in detail in WWDC 2014 session video number 418 "Improving Your App with Instruments", which you can also download as a PDF.

But in short, the syntax is:

autoreleasepool {
  /* code */ 
}



回答2:


Just FYI, Xcode constructed the full code as follows:

autoreleasepool({ () -> () in
    // code              
})

Guess the parentheses identifies the functions closure.




回答3:


There is! It's just not really mentioned anywhere.

autoreleasepool {
    Do things....
}


来源:https://stackoverflow.com/questions/24152050/what-is-the-equivalent-of-autoreleasepool-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!