views:

239

answers:

1

Hello guys!

I am trying to present a modal view controller. I have read the documentation, but something is strange. Here's my code:

NSLog(@"rc: %d", [modalViewController retainCount]);
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:modalViewController];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
NSLog(@"rc: %d", [modalViewController retainCount]);

And on the console, appears:

rc: 2
rc: 24

And I think 24 is very strange... What do you thin? Why is this happening?

+2  A: 

You shouldn't worry about the value of retain count too much. When using system calls like this, any number of retain/release cycles can occur.

If your view controller is being presented modally correctly, then what's the problem?

Jasarien
There appears a memory leak after I close my ModalViewController and I can't find where is the leak. :(
Infinity
It's not in this code. Where is modalViewController created?
Jasarien
Ok, I found it. I set a property like this: self.prop = [data retain];I am very angry for myself now...
Infinity
I would not agree with "don't worry about the retain count too much" ... as Infinity stated, they found the issue with the [data retain] call and that would've caused an issue later on. It is NEVER right to "not worry about retain count".
Jann