Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-21-2010, 12:32 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 50
tiltem is on a distinguished road
Default Memory management question

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!!!
tiltem is offline   Reply With Quote
Old 10-21-2010, 12:49 AM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Are you expecting rvc to be pointing to a pre-existing controller in your app? As far as I can see you're creating a brand new instance of the RootViewController class, calling the addEventName: method on it, and then immediately destroying it with [rvc release].

Is that what you want, or were you trying to get a pointer to an existing instance of RootViewController? You'd have to go through the AppDelegate or create your own singleton class for that.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 10-21-2010, 11:48 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 50
tiltem is on a distinguished road
Default

Yes, I wanted to get access to the existing (original) RootViewController, but was unsure about how to do that from inside the new UIViewController. How would I go about creating a singleton class, and how can it be accessed through the app delegate?

I appreciate the help!!
tiltem is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 333
9 members and 324 guests
condor304, Desert Diva, dre, hain, mottdog, oceanlablight, palme2elie, schmallegory
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,658
Threads: 94,118
Posts: 402,895
Top Poster: BrianSlick (7,990)
Welcome to our newest member, palme2elie
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:10 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0