i usually dont check the retain count untill the program leaks. But today开发者_JS百科 (i donno y) i checked the retain count and now i am confused.
NSString *strErrorMessage;
strErrorMessage= [NSString stringWithFormat:@"Email and Password are mandatory"];
NSLog(@"%d", [strErrorMessage retainCount]); // retain count 1
[objAppDelegate ShowMesssage:strErrorMessage];
NSLog(@"%d", [strErrorMessage retainCount]); // retain count 3
return;
I don get this. As i dont alloc strErrorMessage, i don have to release it rite?
who has the owner ship of strErrorMessage.
-(void) ShowMesssage: (NSString *)strError
{
UIAlertView *alertError = [[UIAlertView alloc] initWithTitle:strTitle message:strError delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertError show];
[alertError release];
}
Do i have to release strError here?(i thought no, but what abt the retain count 3).
Checking the retain count generally isn't a good way to debug memory leaks, so I wouldn't worry too much about it as long as you understand where you're allocating/releasing memory. Here you're autoreleasing the error message and manually releasing the alertError so I think you're okay.
I would guess that the two extra retains are in the UIAlertView
. It's going to have to retain the error message string at least once to work correctly. The second retain is probably just some internal implementation detail.
精彩评论