UIAlertView -show causing a memory leak
Posted
by Erik
on Stack Overflow
See other posts from Stack Overflow
or by Erik
Published on 2010-05-19T01:44:47Z
Indexed on
2010/05/19
1:50 UTC
Read the original article
Hit count: 780
I'm relatively new to iPhone Development, so this may be my fault, but it goes against what I've seen. :)
I think that I'm creating a UIAlertView that lives just in this vaccuum of the 'if' statement.
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if(!data)
{
// Add an alert
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Unable to contact server"
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
NSLog(@"retain count before show: %i", alert.retainCount);
[alert show];
NSLog(@"retain count before release: %i", alert.retainCount);
[alert release];
NSLog(@"retain count after release: %i", alert.retainCount);
return nil;
}
However, the console logs baffle me.
retain count before show: 1
retain count before release: 6
retain count after release: 5
I've tried also adding:
alert = nil;
after the release. That makes the retain count 0, but I still show a leak. And if it helps, the leak's Responsible Frame is UIKeyboardInputManagerClassForInputMode. I'm also using OS 4 Beta 3.
So anyone have any ideas how a local UIAlertView's retain count would increment itself by 5 when calling -show?
Thanks for your help!
© Stack Overflow or respective owner