title: ios : change window.rootViewController and memory management
body: <p>I'm facing the following problem : My app has two main controller (a)loginController and (b) contentController, when the app is launched I check if the user is logged in if yes I show the contentController otherwise I show the login controller. So basically in didFinishLaunchingWithOptions I assign one of this controller to window.rootViewController. The problem is when I want to switch from one controller to the other (because the user made a login or logout) to accomplish this I use the following code :</p>
  
  <pre><code>[UIView transitionWithView:self.window
                    duration:0.65
                     options:UIViewAnimationOptionTransitionFlipFromLeft
                  animations:^{
                      self.window.rootViewController = self.contentController;
                  }
                  completion:^(BOOL finished){
                      [self.loginController release];
                  }];
  </code></pre>
  
  <p>before this transition window.rootViewController was loginController, the problem here is that when this code is executed I receive the following error:</p>
  
  <pre><code>-[loginController _preferredInterfaceOrientationGivenCurrentOrientation:]: message sent to deallocated instance 0x1c55b490
  </code></pre>
  
  <p>I would like to understand how can I release my controller without getting this error.
  It would be also great if someone could suggest me what is the best approach to change  window.rootViewController at runtime.</p>