views:

26

answers:

1

On a number of view controllers in my app, it seems to get overreleased such that when I pop the view controller (i.e. the user hits "back"), I get a crash. I am using fairly standard code to declare and load the UIViewController:

  MyViewController *myVC = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
  NSManagedObjectContext *context = [self managedObjectContext];
  if (!context) {
   // TODO: handle the error
  }
  // pass the managed object context to the view controller.
  myVC.managedObjectContext = context;
  myVC.variable1 = self.variable1;
  // Pass the selected object to the new view controller.
  [self.navigationController pushViewController:myVC animated:YES];
  [myVC release];

And then I get this error:

2010-08-05 16:28:50.733 MyApp[2510:207] *** -[CALayer release]: message sent to deallocated instance 0x719c260

According to Instruments, I have the following memory actions:

  1. Malloc (1) in the function which I posted above.
  2. Zombie (-1) in some Objective-C area which I presume is the memory management code.

Any idea what would be causing this? For now I have been simply not release-ing the view controllers which are causing this problem, but I know this cannot be good since you should be releasing anything that you alloc.

A: 

Your code alternatively mentions the variables vc, myVC and importVC. Is this functioning code? If it is, I'm surprised it works at all, and there must be a lot more going on behind the scenes.

Shaggy Frog
Sorry, I copied the code wrong--it should actually all be myVC, not anything else. (I changed the real variable names to something more generic and obviously screwed up in the process)
Jason
Shaggy Frog