Reputation: 24481
I just ran the clang static analyzer on my project, and I am receiving the following warning:
Incorrect decrement of the reference count of an object that is not owned at this point by the caller
Please can you tell me what my problem is. I usually am able manage the memory used in my app very well.
self.cupboardViewController = [[CupboardViewController alloc] initWithNibName:@"CupboardViewController" bundle:[NSBundle mainBundle]];
[self.window addSubview:self.cupboardViewController.view];
- (void)dealloc {
[[self cupboardViewController] release];//where I am getting the warning.
[super dealloc];
}
Upvotes: 1
Views: 553
Reputation: 902
If you have cupboardViewController
as a retained property then setting self.cupboardViewController =
in the above code creates a retain count of 2.
The problem is its over retained, so when you release it in dealloc there is still an outstanding retain and thus it leaks.
A code standard I use is simply:
theProperty = [[NS* alloc] init]
When I alloc my property (creating a single retain), then just:
[theProperty release];
In my dealloc
method.
This way I am consistent in that I don't reference the property, only the iVar and sidestep these issues with over or under retain and release.
Upvotes: 0
Reputation: 723408
Pretty sure you should be releasing the instance variable, not the property.
- (void)dealloc {
[cupboardViewController release];
[super dealloc];
}
Upvotes: 3