0

I'm getting an odd error. We are using iOS 5 with ARC. When NSZombiesEnabled is set to true and the app is plugged into the debugger we get this error (it happens normally too but not as consistently)

2012-07-04 11:25:17.161 Trivial[624:707] -[vcCurrentGames gamesLoaded:] [Line 284] Found 62 games that are my turn.
2012-07-04 11:25:17.162 Trivial[624:707] -[vcCurrentGames gamesLoaded:] [Line 285] Found 26 games that are their turn.
2012-07-04 11:25:17.169 Trivial[624:707] -[vcCurrentGames tableView:heightForHeaderInSection:] [Line 409] Height 1: 29
2012-07-04 11:25:17.171 Trivial[624:707] *** -[vcDashboard retain]: message sent to deallocated instance 0xf62c3c0

We are not retaining the dashboard anywhere (ARC doesn't allow retain). This only happens after the app is loaded from the background. vcCurrentGames is actually a UITableView on the dashboard. Which makes it even more odd to me, because if the dashboard is dealloced then why is it's UITableView loading?

I've read a little bit about this. The dashboard is defined in the app delegate as a property:

@property (nonatomic, strong) vcDashboard *vDashboard;

I've attempted making this weak so that it will zero out, but that doesn't work either. Can someone tell me why it's being dealloced or why it's trying to retain vcDashboard after it's been dealloced?

In app delegate I declare it like this:

UIViewController *viewController = [[vcDashboard alloc] initWithNibName:@"vcDashboard" bundle:nil];
self.vDashboard = (vcDashboard *)viewController;
Matt Hudson
  • 7,329
  • 5
  • 49
  • 66

1 Answers1

1

Maybe something goes wrong during initialization. You assign the vcDashboard to a UIViewController and then cast that controller to the appropriate class. While theoretically this should be fine, I have never seen this pattern before. The standard way is:

self.vDashboard = (vcDashboard*) [[vcDashboard alloc] init];

assuming that the nib name is "vcDashboard" (as seems to be the case) and that the class in the nib is also "vcDashboard".
(BTW, the convention is to capitalize class names.)

Also, after the app goes into the background, maybe vcDashboard gets deallocated. In any case, it is not guaranteed that it is still there when the app comes back from background. Did you consider lazy instantiation?

// in app delegate
-(vcDashboard*)vDashboard {
   if (_vcDashboard) {
     return _vcDashboard;
   }

   vcDasboard vc = [[vcDashboard alloc] init];
   // more initialization code
   _vcDashboard = vc;
   return vc;
}
Mundi
  • 79,884
  • 17
  • 117
  • 140