在@autoreleasepool中創建的變量,會在@autoreleasepool結束的時候執行一次release,進行釋放。其實@autoreleasepool就相當于一層作用域。
ARC 并不是舍棄了 @autoreleasepool
,而是在編譯階段幫你插入必要的 retain
/release
/autorelease
的代碼調用。
所以,跟你想象的不一樣,ARC 之下依然是延時釋放的,依然是依賴于 NSAutoreleasePool
,跟非 ARC 模式下手動調用那些函數本質上毫無差別,只是編譯器來做會保證引用計數的正確性。
新聞熱點
疑難解答