title: dismissViewControllerAnimated crash at ios5
body: <p>Does the code crash, because of a circular reference?</p>
  
  <pre><code>MenuController: UIViewController
  
  - (id)initWithNibName:
  {...
  TabsController *tabs = [[TabsController alloc] initWithNibName:@"TabsController" bundle:nil];
  self.tab = tabs;
  ....
  }
  
  //button pressed:
  - (IBAction)showPrefFromMenu:(id)sender {
      // todo change delegate!?
       tab.tabDelegate = self;
      [self presentModalViewController:tab animated:YES];
      //[tab release];
  }
  
  // delegate method:
   -(void)myViewDismissed {
      .... 
      NSLog(@"tab references: %d", [tab retainCount]) ;
  
      [self dismissModalViewControllerAnimated:YES];//crash       
       ...
  
  }
  </code></pre>
  
  <p>the modal / child class:</p>
  
  <pre><code>TabsController : UIViewController &lt;...&gt;
  
  - (IBAction)dismissTabs:(id)sender {
        ...
      NSLog(@"dismissTabs: sender: %@",sender);
      [self.tabDelegate myViewDismissed];    
  }
  </code></pre>
  
  <p>As I see the self.tabDelegate is the MenuController instance and on that code want do dismiss and deallocate the TabsController.</p>
  
  <p>Although it isn't any more code after [self.tabDelegate myViewDismissed];  but if it would be than couldn't execute, because it is deallocated, maybe the assembly Ret or what instruction can't be executed? the return statement.</p>
  
  <p>I will try to separate the delegate or any better solution?</p>
  
  <p>Edit:
  The crash is the typical one: EXC_BAD_ACCESS(code=1,address=090)
  the Assembly looks like this: 
  ldr    r1, [r4, r0]</p>
  
  <p>Edit2:
  changed a bit the code, because in simulator 4.3 doesn't crash, but at 5.0 it is, now here is the current code:</p>
  
  <pre><code>- (IBAction)showTab:(id)sender {
  
      tab.tabDelegate = self;
  
      if (SYSTEM_VERSION_LESS_THAN(@"5.0")) {
          [self presentModalViewController:tab animated:YES];
      }
      else{
          NSLog(@"Executing presentViewController (ios&gt;= 5.0)");
          [self presentViewController:tab animated:true completion: nil];
      }
  
  }
  
  
   -(void)delegateCallback {
  
       if (SYSTEM_VERSION_LESS_THAN(@"5.0")) {
           [self dismissModalViewControllerAnimated:NO]; 
       }
       else{
           NSLog(@"Executing dismissViewControllerAnimated (ios&gt;= 5.0)");
           [self dismissViewControllerAnimated:TRUE completion: nil];//crash
       }        
  
  }
  </code></pre>
  
  <p>Edit3 screenshot:</p>
  
  <p><img src="https://i.stack.imgur.com/8Oepz.png" alt="threads"></p>
  
  <p>UIWindowController transition:fromViewController:toViewController:didEndSeelctor line is crashing, due to: no parentViewController:
  <a href="https://devforums.apple.com/message/451045" rel="nofollow noreferrer">https://devforums.apple.com/message/451045</a>
  Guys here found a solution, : <a href="https://github.com/ideashower/ShareKit/issues/254" rel="nofollow noreferrer">https://github.com/ideashower/ShareKit/issues/254</a> but in under NDA</p>
  
  <p>Edit solved to revrite to PushviewController for ios 5.0+
  a heplfull link: <a href="https://stackoverflow.com/a/7767767/529543">https://stackoverflow.com/a/7767767/529543</a></p>
  
  <pre><code>- (IBAction)presentViewController:(id)sender {
  
  
      tab.tabDelegate = self;
  
      if (SYSTEM_VERSION_LESS_THAN(@"5.0")) {
          [self presentModalViewController:tab animated:FALSE];
      }
      else{
          NSLog(@"Executing presentViewController (ios&gt;= 5.0) [tab retainCount]: %d " ,[tab retainCount]);       
  
      // store parent view to able to restore the state:
      parentView = self.view.superview;        
  
      // init a navigation controler and set up:
      navigationController=[[UINavigationController alloc] initWithRootViewController:self];                
      [self.view removeFromSuperview];
  
      [myAppDelegate.window addSubview:navigationController.view];   ///appDelegate is delegate of ur Application     
  
      navigationController.navigationBar.hidden =true;
  
      [navigationController pushViewController:tab animated:YES];       
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and popping:</p>
  
  <pre><code>-(void)infoViewDismissed {
  
       if (SYSTEM_VERSION_LESS_THAN(@"5.0")) {
  
           [self dismissModalViewControllerAnimated:NO];  
       }
       else{
           NSLog(@"Executing dismissViewControllerAnimated (ios&gt;= 5.0) ");
  
           [navigationController popToRootViewControllerAnimated:false];        
  
           [navigationController.view removeFromSuperview];
  
           [parentView addSubview:self.view];
  
       }     
  }
  </code></pre>
  
  <p>I have solved my problem, in a very ugly mode, but is functional...Also told to drop the support for ios3 :) I don't like the GUI architecture switch at runtime at all.</p>