{"id":25443,"date":"2019-05-31T15:38:28","date_gmt":"2019-05-31T19:38:28","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=25443"},"modified":"2019-05-31T15:38:28","modified_gmt":"2019-05-31T19:38:28","slug":"autoreleasepool-uses-in-2019-swift","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2019\/05\/31\/autoreleasepool-uses-in-2019-swift\/","title":{"rendered":"@autoreleasepool Uses in 2019 Swift"},"content":{"rendered":"<p><a href=\"https:\/\/swiftrocks.com\/autoreleasepool-in-2019-swift.html\">Bruno Rocha<\/a>:<\/p>\n<blockquote cite=\"https:\/\/swiftrocks.com\/autoreleasepool-in-2019-swift.html\"><p>To put it short, <code>autoreleasepool<\/code> is still useful in iOS\/Swift development as there are still legacy Obj-C classes in UIKit and Foundation that call <code>autorelease<\/code>, but you likely don&rsquo;t need to worry about it when dealing with Swift classes due to ARC&rsquo;s optimizations.<\/p><\/blockquote>\n<p>Presumably, pure Swift objects can also be autoreleased when manipulated by Objective-C code. I still find <code>autoreleasepool<\/code> to be useful, both to reduce peak memory use and to ensure that resources associated with objects will be cleaned up at a particular time.<\/p>\n<p>One pain point has been that <code>XCTestCase<\/code> doesn&rsquo;t seem to use pools around its <code>setUp()<\/code> and <code>tearDown()<\/code> methods. This led to log messages from Core Data complaining that the SQLite database had been deleted out from under it when the test was over. An autoreleased controller had been retaining the persistent store coordinator.<\/p>\n<p>I ended up making a subclass of <code>XCTestCase<\/code> with its own lifecycle methods that run inside autorelease pools and are allowed to throw errors.<\/p>","protected":false},"excerpt":{"rendered":"<p>Bruno Rocha: To put it short, autoreleasepool is still useful in iOS\/Swift development as there are still legacy Obj-C classes in UIKit and Foundation that call autorelease, but you likely don&rsquo;t need to worry about it when dealing with Swift classes due to ARC&rsquo;s optimizations. Presumably, pure Swift objects can also be autoreleased when manipulated [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2019-05-31T19:38:31Z","apple_news_api_id":"5efabb9c-f8d4-4704-9c33-08b53a7a4679","apple_news_api_modified_at":"2019-05-31T19:38:33Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AXvq7nPjURwScMwi1OnpGeQ","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[55,109,30,1609,571,71,901,268],"class_list":["post-25443","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-arc","tag-coredata","tag-mac","tag-macos-10-14","tag-memory-management","tag-programming","tag-swift-programming-language","tag-testing"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/25443","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=25443"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/25443\/revisions"}],"predecessor-version":[{"id":25444,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/25443\/revisions\/25444"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=25443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=25443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=25443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}