<div dir="ltr"><div class="">

        <p>Here's a little example of using weak arguments:</p>

<pre style class=""><code><span class="">@interface</span><span class=""> </span><span class="">MYTestObject</span><span class=""> </span><span class="">:</span><span class=""> </span><span class="">NSObject</span><span class="">

</span><span class="">@end</span><span class="">

</span><span class="">@implementation</span><span class=""> </span><span class="">MYTestObject</span><span class=""> </span><span class="">{</span><span class="">
   </span><span class="">void</span><span class="">(^</span><span class="">_block</span><span class="">)(</span><span class="">void</span><span class="">);</span><span class="">
</span><span class="">}</span><span class="">

</span><span class="">-</span><span class=""> </span><span class="">(</span><span class="">void</span><span class="">)</span><span class="">dealloc </span><span class="">{</span><span class="">
   </span><span class="">NSLog</span><span class="">(@</span><span class="">"DEALLOC!"</span><span class="">);</span><span class="">
</span><span class="">}</span><span class="">

</span><span class="">-</span><span class=""> </span><span class="">(</span><span class="">id</span><span class="">)</span><span class="">init </span><span class="">{</span><span class="">
   </span><span class="">if</span><span class=""> </span><span class="">(</span><span class="">self </span><span class="">=</span><span class=""> </span><span class="">[</span><span class="">super init</span><span class="">])</span><span class=""> </span><span class="">{</span><span class="">
      </span><span class="">[</span><span class="">self doSomethingWithObject</span><span class="">:</span><span class="">self</span><span class="">];</span><span class="">
   </span><span class="">}</span><span class="">
   </span><span class="">return</span><span class=""> self</span><span class="">;</span><span class="">
</span><span class="">}</span><span class="">

</span><span class="">-</span><span class=""> </span><span class="">(</span><span class="">void</span><span class="">)</span><span class="">doSomethingWithObject</span><span class="">:(</span><span class="">id __weak </span><span class="">/* <- weak argument! */</span><span class="">)</span><span class="">obj </span><span class="">{</span><span class="">
   _block </span><span class="">=</span><span class=""> </span><span class="">^{</span><span class="">
      </span><span class="">NSLog</span><span class="">(@</span><span class="">"%p"</span><span class="">,</span><span class=""> obj</span><span class="">);</span><span class="">
   </span><span class="">};</span><span class="">
</span><span class="">}</span><span class="">

</span><span class="">@end</span></code></pre>

<p>And it works: <code>-dealloc</code> is called!
Also, if you remove <code>__weak</code> you'll get a retain-cycle and it's absolutely correct.</p>

<p>Wonder, if that's just a side-effect and it's completely unsafe to 
use weak arguments? Or is it a specified behavior and I'm just a bad 
google-user?</p><p><br></p><p>P.S.</p><p>Here's my question on SO: <a href="http://stackoverflow.com/questions/18316803/objective-c-arc-is-it-correct-to-use-weak-arguments">http://stackoverflow.com/questions/18316803/objective-c-arc-is-it-correct-to-use-weak-arguments</a><br>
</p>

    </div></div>