Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

tiltem

macrumors newbie
Original poster
Oct 18, 2010
25
0
I have navigation based template, using core data(not sure if that matters), and a UIViewController as a second view. I get to the second view by clicking the add (+) button in the top right of the navigation bar. In here I have the top right button of the navigation controller call my save method when clicked. In this save method I create a RootViewController object and call one of the rootView's methods and then pop back to the root view.

The issue is that if I release this root view object the app crashes, if I do not release the object it seems to work fine. I just need to know if this is causing a memory leak?

Here is the code for the save method, this is in my UIViewController, the RootViewController is a UITableViewController:

Code:
-(void) save{
	if ([newEventName.text length]== 0) {
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Missing Event Name" message:@"Please enter an event name or Cancel." delegate:self cancelButtonTitle:@"DONE" otherButtonTitles:nil];
		[alert show];
		[alert release];
		return;
	}
	eventDate = dateStartedPicked.date;
	RootViewController *rvc =[[RootViewController alloc] initWithNibName:nil bundle:nil];
	[rvc addEventName:newEventName.text eventDate:eventDate];
	[self.navigationController popToRootViewControllerAnimated:YES];
//	[rvc release];   <--- Dies here if released
}

I feel like the rvc object is now considered self since I have popped back to its view, and thus may not need to be released. I don't know but would like to know for sure.

Thanks!!!
 
In this save method I create a RootViewController object and call one of the rootView's methods and then pop back to the root view.
Why create another RootViewController when you already have one instantiated?: the one controlling the initial table view and that calls up the second view. Rather than create a new one, find a way to get access to the existing one.

Code:
	RootViewController *rvc =[[RootViewController alloc] initWithNibName:nil bundle:nil];
	[rvc addEventName:newEventName.text eventDate:eventDate];
	[self.navigationController popToRootViewControllerAnimated:YES];
//	[rvc release];   <--- Dies here if released
}

I feel like the rvc object is now considered self since I have popped back to its view, and thus may not need to be released. I don't know but would like to know for sure.
No, the rvc object is not self; self will always be the current instance of the object of the class that you're within.
 
Yes I would rather not create another RootViewController, but am unsure about how to reference the existing one. How would I reference the original RootViewController object from within the new UIViewController?
 
How would I reference the original RootViewController object from within the new UIViewController?
One way would be to tell it about it (i.e. set up a property for the RootViewController in the UIViewController and then set it after you've instantiated the UIViewController.)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.