简体   繁体   中英

Issue found in Xcode 5.1.1 and not in Xcode 6

I have a problem if i build my application from Xcode 5 and run the same on a device with iOS 8 i see a crash with a error message

[myViewController numberOfSectionsInTableView:] message sent to deallocated instance 0x1846c960

I have allocated the class as below

@property (strong, nonatomic) MyViewController *myViewController;

myViewController =[[MyViewController alloc]initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]];
myViewController.userDetailsDict=userDetailsDict;
[self.navController pushViewController:self.myViewController animated:FALSE];

if i build the same application from Xcode 6, then i don't see any issue, it works fine.

Has any one faced an issue of similar kind. Any Help ?

That warning appears as a result of having NSZombieEnabled enabled in your build scheme (see linked question).

At some point, [MyViewController numberOfSectionsInTableView:] is being called when MyViewController no longer exists - there were no more references to the object so it was deallocated.


As for why this happens on Xcode 5 and not Xcode 6, this is likely a result of your app's configuration or state in the simulator compared to the device - for example, does one environment contain data or settings that the other does not?

From your code, I can see that MyViewController is probably a UITableViewDataSource . Does one device/simulator contain table view data that the other does not? If so, that is why the error would appear in one environment but not the other. It would appear in both, but only one has the necessary settings/configuration in order to trigger the method being called.

In order to resolve the problem, you need to monitor the object lifecycle of MyViewController - that is, when is it created, when is it accessed and when is it/might it be released. At some point your view controller is being released when you still want to use it. This StackOverflow answer provides an excellent guide on how to use Instruments to track down and fix these sorts of errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM