title: ARC and __unsafe_unretained
body: <p>I think I have a pretty good understanding of ARC and the proper use cases for selecting an appropriate lifetime qualifiers (<code>__strong</code>, <code>__weak</code>, <code>__unsafe_unretained</code>, and <code>__autoreleasing</code>).  However, in my testing, I've found one example that doesn't make sense to me.</p>
  
  <p>As I understand it, both <code>__weak</code> and <code>__unsafe_unretained</code> do not add a retain count.  Therefore, if there are no other <code>__strong</code> pointers to the object, it is instantly deallocated (with immutable strings being an exception to this rule).  The only difference in this process is that <code>__weak</code> pointers are set to nil, and <code>__unsafe_unretained</code> pointers are left alone.</p>
  
  <p>If I create a <code>__weak</code> pointer to a simple, custom object (composed of one NSString property), I see the expected (null) value when trying to access a property:</p>
  
  <pre><code>Test * __weak myTest = [[Test alloc] init];
  myTest.myVal = @"Hi!";
  NSLog(@"Value: %@", myTest.myVal); // Prints Value: (null)
  </code></pre>
  
  <p>Similarly, I would expect the <code>__unsafe_unretained</code> lifetime qualifier to cause a crash, due to the resulting dangling pointer.  However, it doesn't.  In this next test, I see the actual value:</p>
  
  <pre><code>Test * __unsafe_unretained myTest = [[Test alloc] init];
  myTest.myVal = @"Hi!";
  NSLog(@"Value: %@", myTest.myVal); // Prints Value: Hi!
  </code></pre>
  
  <p>Why doesn't the <code>__unsafe_unretained</code> object become deallocated?</p>
  
  <p><strong>[EDIT]</strong>: The object is being deallocated... if I try to substitute lines 2 - 3 with <code>NSLog(@"%@", myTest);</code> the app crashes (and an overridden <code>dealloc</code> in <code>Test</code> is being called immediately after the first line).  I know that immutable strings will continue to be available even with <code>__unsafe_unretained</code>, and that a direct pointer to the NSString would work.  I am just surprised that I could set a property on a deallocated object (line 2), and that it could later be dereferenced from a pointer to the deallocated object it belonged to (line 3)!  If anyone could explain that, it would definitely answer my question.</p>