I use this code ti open a viewcontroller
self.secondViewController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
[self presentModalViewController:self.secondViewController animated:YES];
[self.secondViewController release];
but if i use [self.secondViewController release];
when I call this code second time it crash because
[FirstViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0x18a890
if I don't use it, it it's all ok, but in this situation when can I dealloc my secondviewcontroller? can you help me?
From your code (
self.secondViewController
), my understanding is that you have declaredsecondViewController
as a variable in your .h file, and@synthesize
'd it in your .m file. If that's right, I would rather do the followingsand in your
- (void)dealloc
method, I would add[self.secondViewController release];
and in- (void)viewDidUnload
I would add[self setSecondViewController:nil];
.The above code is with the assumption that you are not using ARC. If you are using ARC, I would revise my code as follows: