views:

70

answers:

2

To use presentModalViewController I must alloc and initWithNibName:bundle: a view. My question is: where do I release it? Does the dismissModalViewController:animated: handle the release?

+4  A: 

You can release after you present the controller; the presenting controller (its parent) will retain your modal controller.

Ben Gottlieb
+2  A: 

No. If you allocatet and initialized it, than you have to release it. Do it like this:

YourViewController *controller = [[YourViewController alloc] initWithNibName:@"YourView" bundle:nil];
[self presentModalViewController:controller animated:YES];
[controller release];

PresentModalViewController:animated: increases automatically the retainCount. And as soon as the controller disappeared from the view, it will release the controller. And so the controller will be deallocated. ;-)

Sandro Meier