Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PresentModalViewController: Where to release?

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?

like image 734
Derek Avatar asked Mar 23 '26 10:03

Derek


1 Answers

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. ;-)

like image 91
Sandro Meier Avatar answered Mar 25 '26 23:03

Sandro Meier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!