0
votes

Pushing my view controller twice to navigation controller and simulating memory warning, lead to application crash with error: "message sent to deallocated instance"

I'm pushing view controller by pressing on button:

-(void)buttonPressed
{
    MyViewCOntroller *vc = [[MyViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}
  • I'm using ARC.

Scenario:

  1. [self buttonPressed];
  2. Press back button in vc.
  3. [self buttonPressed];
  4. Press back button in vc
  5. Simulate memory warning

The crash does not happen if pushing only once.

I tried also to move "vc" to be ivar of parent controller, but the effect is the same...

Maybe this will help, but I'm using custom back button and its selector:

-(void)backButtonPressed
{
    [self.navigationController popViewControllerAnimated:YES];
}
2
Enable zombie, and debug itSuhail kalathil
Did that already. It points to "buttonPressed" method. This is how I found the place. But I can't understand the reason and how to handle it.Misha
Try pushing with segueSuhail kalathil
are you trying to access the parent vc from MyViewCOntroller?jithinroy
push any view controller before viewDid appear will also cause to crash in iOS7 can you tell me same problem occur if you wait for a while when push view in second time?Jageen

2 Answers

0
votes

create this vc object as class member and check if crash exists

 @interface ParentViewController()
 {
    MyViewCOntroller *vc;
 }
 @end

 @implementation PaintingViewController


  -(void)buttonPressed
  {
     vc = [[MyViewController alloc] init];
     [self.navigationController pushViewController:vc animated:YES];
  }
0
votes

Found a solution to this. Please see my answer to my other question:

[UINavigationController retain]: message sent to deallocated instance