title: Dealloc Being Called Twice?
body: <p><strong>Resloved!</strong></p>
  
  <p><strong>Thanks to Lone Gunman, this issue was due to an oversight of not setting the many delegates to nil before releasing them.</strong>  </p>
  
  <p>This is a strange one...  I'm familiar with basic memory management but I think something is unusual about what I am seeing.  Here is a little background... </p>
  
  <p>I have a NavigationController that handles the navigation between the following ViewControllers:</p>
  
  <p>Home -> Games -> Game</p>
  
  <p>When running the code it falls down when leaving the Game.  Within the GameViewController there is a dealloc method that resembles:</p>
  
  <pre><code>- (void)dealloc 
  {
      [board release];
      [opponentsViewController release];
      [instructionsViewController release];
      [imgPicker release];
      [gameView release];
      [super dealloc];
  }
  </code></pre>
  
  <p>When the navigation controller goes back to the Games list (from the Game) it throws a EXC_BAD_ACCESS.  So I bring up my trusty profiler and check for Zombies.  Alas, just as I expected a message is being sent to a deallocated object!  Digging deeper I find there to be 3 entries in the object's history:</p>
  
  <ol>
  <li>Board getting alloc'd (called by Game's init method)</li>
  <li>Board getting released (called by Game's dealloc method)</li>
  <li>Board being Zombie'd (called by Game's dealloc method)</li>
  </ol>
  
  <p>Both calls 2 and 3 are called from UINavigationController setDisappearingViewController.</p>
  
  <p>In my dealloc method I set breakpoints to each release call, when doing so - the [board release] call occurs, then the [opponentsViewController release] call occurs then the [board release] call occurs again.  So I'm seeing the dealloc method does not finish completely and calls again.</p>
  
  <p>What might be causing this?</p>
  
  <p>Edit: This is the <a href="https://gist.github.com/84f1e1026d4201fa6bc1" rel="nofollow">GameViewController Implementation</a></p>
  
  <p>Code from the Games controller that adds this game:</p>
  
  <pre><code>-(void) gotoGame:(int)tag {
  
      game = [[GameViewController alloc] init];
      [self.navigationController pushViewController:game animated:YES];
      [game release];
  
  }
  </code></pre>
  
  <p>Edit: This is the <a href="https://gist.github.com/32a13d2b1a95fe0f7ee5" rel="nofollow">GameViewController Header</a></p>