views:

108

answers:

2
SettingsView *settings = [[SettingsView alloc] initWithNibName:@"SettingsView" bundle:[NSBundle mainBundle]];
settings.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.navigationController presentModalViewController:settings animated:YES];
settings = nil;
[settings release];

Instruments claims that the following line is leaking

[self.navigationController presentModalViewController:settings animated:YES];

Can anyone help me out here? Thank you so much!

+13  A: 

You need to release settings before setting it to nil, not after!

What you're doing now is the same as:

settings = nil;
[nil release];

So the -release is being sent to nil, not to your SettingsView object. (And sending any message to nil is a NOOP).

David Gelhar
A: 

Right. Since 'settings' was never set up with a @property and @synthesize, setting it to nil just erases the memory address it is holding.

If you had set it up with @property (nonatomic, retain) SettingsView *settings;

then a later call to settings = nil;

would also send a [settings release] message.

fogelbaby
FWIW, the statement `settings = nil` will not call the accessor setter method even if settings is a declared property; it will simply set the ivar to nil. You'd need to do `self.settings = nil;` to get the behavior you're describing.
quixoto