views:

81

answers:

2

I have extra retain counts after calling initWithNib. What could cause this? (There are no referencing outlets in the nib)

StepViewController *stepViewController = [[StepViewController alloc] initWithNibName:@"StepViewController" bundle:nil];
[self.navigationController pushViewController:stepViewController animated:YES];
[stepViewController release];
NSLog(@"nextStep stepViewController retain count %i", [stepViewController retainCount]);

the above results in a retain count of 3...

Thanks for any advice on how to troubleshoot

A: 

You would have to look into the source code or API documentation to find out. But it would seem logical that the nvaigation controller has one and the view loaded out of the xib has one, so that's probably another being done by something in the naviation controller would be my guess.

Derek Clarkson
+7  A: 

What are you troubleshooting? There is nothing wrong here. -retainCount is not your business and tells you almost nothing about the system. Every object that is autoreleased will have an apparent retainCount higher than you think it will be. If internal objects are interested in this object, they will have their own retains that you may or may not expect.

Your business is to balance your own retains and releases. The rest of the system is responsible for balancing theirs. You should not second-guess it, and if you do, -retainCount is unlikely to help you much anyway. It is almost always more misleading than helpful.

Is there actually a leak going on that you're concerned about?

Rob Napier
+100 `retainCount` should be obliterated from the Cocoa frameworks. To look at it and wonder what's going on causes nothing but grief. Forget that it exists, and your life will be simpler.
Dave DeLong
Rob - You are right - I was troubleshooting a retain count issue that I caused...didn't relaize that it is ok the retain count was higher than anticipated. After fixing my retain issue everything worked.BTW - The issue was caused because another owned object had a property set using retain instead of assign....Thanks for your help
+1,000,000 what Dave said.
JeremyP