<div dir="ltr"><span style="font-size:13px">In swift it is possible to pass instance method into function parameter that takes closure. But while closure allows to make self unowned, passing instance method does not provide syntax to make self unowned, while instance method creates strong self reference, those creating retain cycle.</span><div style="font-size:13px">This leads to leaks that are not obvious at first glance, and some might be very small and be left unnoticed for some time resulting in hard debugging later.<br><div><br></div><div>For example:</div><div><br></div><div><p style="margin:0px;font-size:12px;line-height:normal;font-family:menlo">        <span style="color:rgb(187,44,162)">self</span>.selectedPlayer.asObserv<wbr>able().subscribeNext(<span style="color:rgb(187,44,162)">self</span>.<wbr>selectedPlayerDidChange).<wbr>addDisposableTo(disposeBag)</p><p style="margin:0px;font-size:12px;line-height:normal;font-family:menlo"><br></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:menlo">creates retain cycle, which is easy mistake to make and is not obvious at first look, and there is no syntax to make self unowned in this case. One has to wrap method call into closure as follows:</p><p style="margin:0px;font-size:12px;line-height:normal;font-family:menlo"><br></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:menlo"><br></p></div><div><p style="margin:0px;font-size:12px;line-height:normal;font-family:menlo">        <span style="color:rgb(187,44,162)">self</span>.<span style="color:rgb(79,129,135)">selectedPlayer</span>.<span style="color:rgb(49,89,93)">asObserv<wbr>able</span>().<span style="color:rgb(49,89,93)">subscribeNext</span> {[<wbr>unowned <span style="color:rgb(187,44,162)">self</span>] (player) <span style="color:rgb(187,44,162)">in</span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:menlo;color:rgb(49,89,93)"><span style="color:rgb(0,0,0)">            </span><span style="color:rgb(187,44,162)">self</span><span style="color:rgb(0,0,0)">.</span>selectedPlayerDidChange<span style="color:rgb(0,0,0)"><wbr>(player)</span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:menlo">            }.<span style="color:rgb(49,89,93)">addDisposableTo</span>(<span style="color:rgb(79,129,135)">disposeBag</span>)</p><div><br></div><div>See also related StackOverflow question at <a href="http://stackoverflow.com/questions/36764101/retain-cycle-happens-when-passing-method-instead-of-closure" target="_blank">http://stackoverflow.com/qu<wbr>estions/36764101/retain-cycle-<wbr>happens-when-passing-method-<wbr>instead-of-closure</a></div></div><div><br></div><div>I think it would be a good idea to either provide a syntax to mark self as unowned when passing instance method into closure parameter, or to make self unowned implicitly when method is passed instead of closure.</div><div>Of course &quot;Explicit is better than implicit&quot; if there is any case for passing method with strong self reference, so some syntax might be introduced to mark unowned or strong and warning (or error) be raised if method is passed without that mark.</div></div></div>