<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi guys,<div><br></div><div><div>I've been using blocks for a while and found that current behavior is error prone. So I am going to propose to you the better one.</div><div><br></div><div><b>Motivation:</b></div><div><br></div><div>1) The __weak variables in blocks are very common pattern. So having any implicit default behavior makes thing worse.</div><div>2) Some stupid mistakes like: </div><div><br></div><div>__weak typeof (self) theSelf = self;</div><div><br></div><div>...^ {</div><div><span class="Apple-tab-span" style="white-space: pre; ">   </span>theSelf.blabla = ..</div><div><span class="Apple-tab-span" style="white-space: pre; ">       </span>....</div><div><span class="Apple-tab-span" style="white-space: pre; ">      </span></div><div><span class="Apple-tab-span" style="white-space: pre; ">  </span>[self blabla];  // ups, calling self directly is an error</div><div>        _ivar = … // or implicit call to self.</div><div>}</div><div><br></div><div>Retain cycles are very hard to find. I am not saying about trivial ones, that compiler can find, or the Leaks tool. Recently I have 3 retain cycles in my program, no one appeared in Leaks. So the main point is prevent such errors at first place, not to rely on that tool will find it. </div><div><br></div><div><b>Proposition: </b></div><div><br></div><div>Any variable captured in block must have explicit qualifier to specify memory capturing semantic: <b>__retain</b>, <b>__weak</b>, <b>__unsafe_unretained</b>. Qualifier is obligatory, no defaults allowed.</div><div><br></div><div>Code will look something like this:</div><div><br></div><div>1) </div><div>NSString* theLocalVariable = …</div><div><br></div><div>...^ {</div><div><span class="Apple-tab-span" style="white-space: pre; ">      </span>...</div><div><span class="Apple-tab-span" style="white-space: pre; ">       </span><b>__weak</b> self;</div><div><span class="Apple-tab-span" style="white-space: pre; ">      </span>self.blabla  =  ...</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>…</div><div><br></div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>[self blabla:(__retain theLocalVariable)];</div><div>}</div><div><br></div><div>2)</div><div>{</div><div><span class="Apple-tab-span" style="white-space: pre; ">      </span>self.blabla = … // <span style="color: rgb(233, 36, 2); ">compile error: missing memory capture semantic qualifier.</span></div><div><span class="Apple-tab-span" style="white-space: pre; ">     </span>....</div><div>}</div><div><br></div><div>For <b>__block</b> qualifier I propose to leave old behavior (leave the default <b>__retain</b> semantic), because retain cycles with write-to variables are uncommon.</div><div><br></div><div>Regards,</div><div>Yaroslav.</div></div></body></html>