Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This does seem strange. You're right (in your comments) about the 2nd bit of code just being because the memory hasn't been re-used yet. But the 3rd bit of code is stranger. Here is a more simplified test case which shows this strange problem:</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @interface SomeClass : NSObject @end @implementation SomeClass - (void)foo { } @end int main (int argc, const char * argv[]) { @autoreleasepool { SomeClass *objPtr1 = [[SomeClass alloc] init]; __weak SomeClass *weakRef = objPtr1; // [weakRef foo]; [weakRef foo]; objPtr1 = nil; NSLog(@"%p", weakRef); return 0; } } </code></pre> <p>With that line commented out the output is:</p> <pre><code>$ clang -fobjc-arc -framework Foundation test.m -o test -O3 &amp;&amp; ./test 2012-02-12 00:39:42.769 test[6684:707] 0x0 </code></pre> <p>With that line uncommented out the output is:</p> <pre><code>$ clang -fobjc-arc -framework Foundation test.m -o test -O3 &amp;&amp; ./test 2012-02-12 00:42:04.346 test[6688:707] 0x100f13f50 </code></pre> <p>This seems deeply odd and looks entirely like a bug to me. I don't actually know what the answer is but thought I'd post this as an answer to get the ball rolling on figuring out what's going on.</p> <p><strong>Update:</strong></p> <p>If you build this at <code>O0</code> then it seems that <code>weakRef</code> is zeroed only if there are <em>no</em> calls to <code>foo</code>. A single call to <code>foo</code> will mean that it won't get zeroed.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload