{"id":521,"date":"2014-09-04T11:12:48","date_gmt":"2014-09-04T03:12:48","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=521"},"modified":"2016-07-15T13:59:52","modified_gmt":"2016-07-15T05:59:52","slug":"captureing-self-strongly-in-this-block-is-likely-to-lead-to-a-retain-cycle","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/analysis\/2014\/09\/04\/111248521.html","title":{"rendered":"Captureing \u2018self\u2019 strongly in this block is likely to lead to a retain cycle"},"content":{"rendered":"<p>\u8b66\u544a:Captureing \u2018<span style=\"color: #ff0000;\">self<\/span>\u2019 <span style=\"color: #ff0000;\">strongly in this block is likely to lead to a retain cycle<\/span><\/p>\n<p>\u8fd9\u4e2a\u8b66\u544a\u6211\u4eec\u5728\u4f7f\u7528block\u65f6\u4f1a\u7ecf\u5e38\u78b0\u5230\uff0c\u4ec0\u4e48\u539f\u56e0\u5f15\u8d77\u7684\u5462\uff1f\u5176\u5b9e\u662fARC\u673a\u5236\u9020\u6210\u7684<\/p>\n<p>\u5206\u6790\uff1aBlock\u5bf9\u8c61\u5728\u521b\u5efa\u65f6\u4f1aretain\u4e00\u6b21\uff0c\u5982\u679c\u5728block\u4e2d\u4f7f\u7528self.xxx\u65f6\uff0cARC\u4f1a\u81ea\u52a8\u5c06self\u4e5fretain\u4e00\u6b21\uff0c\u8fd9\u6837\u5c31\u5f62\u6210\u4e86\u4e00\u4e2aretain cycle<\/p>\n<p>\u89e3\u51b3\uff1a\u521b\u5efa\u4e00\u4e2a\u672c\u5730\u53d8\u91cfblockSelf\uff0c\u6307\u5411self\uff0c\u7136\u540e\u7528\u7ed3\u6784\u4f53\u8bed\u6cd5\u8bbf\u95ee\u5b9e\u4f8b\u53d8\u91cf\u3002<\/p>\n<p>\u5982\uff1a__block ViewController *blockSelf = self\uff1b<br \/>\n\u7136\u540e\u5728block\u4e2d\u9700\u8981\u7528\u5230self.xxx\u65f6\uff0c\u6539\u6210blockSelf.xxx\u5c31\u53ef\u4ee5\u4e86\uff0c\u56e0\u4e3a\u8fd9\u4e48\u4fee\u6539\u4e4b\u540e\uff0cblockSelf\u662f\u672c\u5730\u53d8\u91cf\uff0c\u662f\u5f31\u5f15\u7528\uff0c\u56e0\u6b64\u5728_block\u88abretain\u7684\u65f6\u5019\uff0c\u5e76\u4e0d\u4f1a\u589e\u52a0retain count\uff0c\u6240\u4ee5retain cycle\u5c31\u89e3\u9664\u4e86\uff0cXcode\u4e5f\u4e0d\u518d\u51fa\u73b0\u8b66\u544a\u4e86\uff0c\u95ee\u9898\u89e3\u51b3\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8b66\u544a:Captureing \u2018self\u2019 strongly in this block is likely to lead to a retain cycle \u8fd9\u4e2a\u8b66\u544a\u6211\u4eec\u5728\u4f7f\u7528block\u65f6\u4f1a\u7ecf\u5e38\u78b0\u5230\uff0c\u4ec0\u4e48\u539f\u56e0\u5f15\u8d77\u7684\u5462\uff1f\u5176\u5b9e\u662fARC\u673a\u5236\u9020\u6210\u7684 \u5206\u6790\uff1aBlock\u5bf9\u8c61\u5728\u521b\u5efa\u65f6\u4f1aretain\u4e00\u6b21\uff0c\u5982\u679c\u5728block\u4e2d\u4f7f\u7528self.xxx\u65f6\uff0cARC\u4f1a\u81ea\u52a8\u5c06self\u4e5fretain\u4e00\u6b21\uff0c\u8fd9\u6837\u5c31\u5f62\u6210\u4e86\u4e00\u4e2aretain cycle \u89e3\u51b3\uff1a\u521b\u5efa\u4e00\u4e2a\u672c\u5730\u53d8\u91cfblockSelf\uff0c\u6307\u5411self\uff0c\u7136\u540e\u7528\u7ed3\u6784\u4f53\u8bed\u6cd5\u8bbf\u95ee\u5b9e\u4f8b\u53d8\u91cf\u3002 \u5982\uff1a__block ViewController *blockSelf = self\uff1b \u7136\u540e\u5728block\u4e2d\u9700\u8981\u7528\u5230self.xxx\u65f6\uff0c\u6539\u6210blockSelf.xxx\u5c31\u53ef\u4ee5\u4e86\uff0c\u56e0\u4e3a\u8fd9\u4e48\u4fee\u6539\u4e4b\u540e\uff0cblockSelf\u662f\u672c\u5730\u53d8\u91cf\uff0c\u662f\u5f31\u5f15\u7528\uff0c\u56e0\u6b64\u5728_block\u88abretain\u7684\u65f6\u5019\uff0c\u5e76\u4e0d\u4f1a\u589e\u52a0retain count\uff0c\u6240\u4ee5retain cycle\u5c31\u89e3\u9664\u4e86\uff0cXcode\u4e5f\u4e0d\u518d\u51fa\u73b0\u8b66\u544a\u4e86\uff0c\u95ee\u9898\u89e3\u51b3\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[17],"class_list":["post-521","post","type-post","status-publish","format-standard","hentry","category-analysis","tag-skill"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=521"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/521\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}