views:

19

answers:

2

Hi

I was watching the videos from WWDC 2010 and have now started to dig in to the functionality of the Build and Analyze tool in xcode 3.2. It's a great tool that will highlight coding mistakes (specially for a newcomer like me!) even if they may not have an impact during runtime.

But there is one thing I would need some help to understand.

When I push a new view controller with this code:

SettingsViewController *nextController = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];

My_AppAppDelegate *delegate = [[UIApplication sharedApplication] delegate];

[delegate.myNavController pushViewController:nextController animated:YES];

The analyzer tells me there is a potential memory leak. I can understand that in a way, as I allocate the NextController but never release it. But if I try to release it, my app crashes.

I dont get any leaks when analyzing with Instruments on the simulator and physical device.

Would Apple stop this app or would it go through their testing?

A: 

You will probably not be rejected for leaks unless they lead to an unhandled memory warning and crash. That said, the specific problem you mention can be fixed using autorelease.

SettingsViewController *nextController = [[[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil] autorelease];

The navigation controller should retain the view controller for its lifetime.

Justin
Thanks for the proposal. I tested it and it works fine in the build and analyze and the first time I push the controller. The second time I do it the app crashes. How is it with autorelease and iOS? From what I understand there is no garbage collection in iOS, but in some places they still refer to autorelease...
Structurer
I strongly recommend you read Apple's memory management programming guide. I don't have a link handy, but it will answer more questions than any comment here.
Justin
A: 

Submitted the App to Apple and it passed.

Structurer