title: Handling Pointer-to-Pointer Ownership Issues in ARC
body: <p>Suppose <strong>Object A</strong> has a property: </p>
  
  <pre><code>@property (nonatomic, strong) Foo * bar;
  </code></pre>
  
  <p>Synthesized in the implementation as:</p>
  
  <pre><code>@synthesize bar = _bar;
  </code></pre>
  
  <p><strong>Object B</strong> manipulates a <code>Foo **</code>, as in this example call from <strong>Object A</strong>:</p>
  
  <pre><code>Foo * temp = self.bar;
  [objB doSomething:&amp;temp];
  self.bar = temp;
  </code></pre>
  
  <ul>
  <li>Can this, or something similar, be done legitimately?</li>
  <li>What is the correct declaration for the <code>doSomething:</code> method?</li>
  </ul>
  
  <p>Furthermore, suppose <strong>Object B</strong> may be deallocated before I have a chance to set the <code>bar</code> property (and thus take on ownership of the instance pointed to by <code>temp</code>) - How would I tell ARC to hand off an owning reference? In other words, if I wanted the following example snippet to work, how would I need to handle the ARC issues?</p>
  
  <pre><code>Foo * temp = self.bar;    // Give it a reference to some current value
  [objB doSomething:&amp;temp]; // Let it modify the reference
  self.bar = nil;           // Basically release whatever we have
  _bar = temp;              // Since we're getting back an owning reference, bypass setter
  </code></pre>
  
  <ul>
  <li>What aren't I thinking of?</li>
  </ul>
  
  <p><strong>EDIT</strong></p>
  
  <p>Based on @KevinBallard 's answer, I just want to confirm my understanding. Is this correct?</p>
  
  <p><strong>Object A:</strong></p>
  
  <pre><code>@implementation ObjectA
  
  @synthesize bar = _bar;
  
  - (void)someMethod
  {
      ObjectB * objB = [[ObjectB alloc] initWithFoo:&amp;_bar];
      // objB handed off somewhere and eventually it's "doSomething" method is called.
  }
  
  @end
  </code></pre>
  
  <p><strong>Object B:</strong></p>
  
  <pre><code>@implementation ObjectB
  {
      Foo * __autoreleasing * _temp;
  }
  
  - (id)initWithFoo:(Foo * __autoreleasing *)temp
  {
      id self = [super init];
      if (self)
      {
          _temp = temp;
      }
      return self;
  }
  
  - (void)doSomething
  {
      ...
      *_temp = [[Foo alloc] init]; 
      ...
  }
  
  @end
  </code></pre>
  
  <p>This creates a compile-time error: <code>passing address of non-local object to __autoreleasing parameter for write-back</code></p>