{"id":520,"date":"2015-07-20T17:18:01","date_gmt":"2015-07-20T15:18:01","guid":{"rendered":"http:\/\/andras.palfi.hu\/?p=520"},"modified":"2015-07-20T17:18:01","modified_gmt":"2015-07-20T15:18:01","slug":"arc-block-avoid-retain-cycles-and-crashes","status":"publish","type":"post","link":"https:\/\/andras.palfi.hu\/?p=520","title":{"rendered":"ARC-Block-Avoid retain cycles and crashes"},"content":{"rendered":"<p>\t\t\t\tUsing blocks which captures self (explicitly or automatically by referencing an iVar!) you have the chance to a retain cycle where the block keeps self and self keeps the block or a crash when self is released.<\/p>\n<p>This is true for Obj-C as well as for Swift.<\/p>\n<p>The proper usage declared by Apple itself: store <em>self<\/em> in a <em>weak ref<\/em> and in the block put it to\u00a0<em>strong ref<\/em> to avoid the release of self just in the time the code runs.<\/p>\n<p>Apple link:\u00a0<a href=\"https:\/\/developer.apple.com\/library\/mac\/releasenotes\/ObjectiveC\/RN-TransitioningToARC\/Introduction\/Introduction.html\">Transitioning to Arc RC<\/a>\u00a0and search for the section: &#8220;For non-trivial cycles, however, you should use&#8221;<\/p>\n<p>Looks strange but if you think carefully you realize how efficient the solution is.<\/p>\n<p>For a more deeper explanation see:\u00a0<a href=\"https:\/\/dhoerl.wordpress.com\/2013\/04\/23\/i-finally-figured-out-weakself-and-strongself\/\">this post<\/a>\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using blocks which captures self (explicitly or automatically by referencing an iVar!) you have the chance to a retain cycle where the block keeps self and self keeps the block or a crash when self is released. This is true for Obj-C as well as for Swift. The proper usage declared by Apple itself: store [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"hide_page_title":"","footnotes":""},"categories":[16,18,3,4,9],"tags":[],"_links":{"self":[{"href":"https:\/\/andras.palfi.hu\/index.php?rest_route=\/wp\/v2\/posts\/520"}],"collection":[{"href":"https:\/\/andras.palfi.hu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/andras.palfi.hu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/andras.palfi.hu\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/andras.palfi.hu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=520"}],"version-history":[{"count":0,"href":"https:\/\/andras.palfi.hu\/index.php?rest_route=\/wp\/v2\/posts\/520\/revisions"}],"wp:attachment":[{"href":"https:\/\/andras.palfi.hu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/andras.palfi.hu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/andras.palfi.hu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}