codercat
codercat

Reputation: 23271

Why is came and How to fix [UIView release]: message sent to deallocated instance

I have used storyboard for this menu from here.

enter image description here

Every working good but i have to be inalize the UIViewController with block it to crashes it will show below exception

 -[UIView release]: message sent to deallocated instance 0x1b343c30

i search over the google and stackOverflow but not get solution and much more information

code

     __typeof (self) __weak weakSelf = self;
    REMenuItem *homeItem = [[REMenuItem alloc] initWithTitle:@"NEW" subtitle:@"Return to Home Screen" image:[UIImage imageNamed:@"Icon_Home"] highlightedImage:nil   action:^(REMenuItem *item) {
   NSLog(@"Item: %@", item);


MasterViewController  *controller = [[MasterViewController alloc]init];

[weakSelf.navigationController pushViewController:controller animated:YES];

                                                      }];

why it occurs how to solve this

Upvotes: 0

Views: 555

Answers (1)

jrturton
jrturton

Reputation: 119242

It's not possible to be certain from the code you've posted (you haven't said if you're using ARC, or shown the call stack when using zombies), but if all your menu actions look like this, you will be building up an enormous stack of view controllers on the navigation controller, which is going to lead to high memory use. Depending on the rest of your code this could lead to some view being deallocated which is then later released elsewhere.

Your menu action code should probably install the relevant view controller as the root view controller of the navigation stack instead of simply pushing it.

To help track down what the offending object is and where it was created, you can use the Zombies instrument. When you app crashes, open the detail inspector on the right hand side and it will tell you what the view is, what method it was created in and so forth. This is a great help when tracking these sorts of bugs down.

Upvotes: 2

Related Questions