0

I have simple method showing AlertView with textfield. Instruments showing memory leak in this. Please explain.

- (void)method {
NSString *value = [[NSUserDefaults standardUserDefaults] valueForKey:@"key"];
if (value == nil) {

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

    alertView.tag = 101;
    alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
    UITextField *txtGroup = [alertView textFieldAtIndex:0];
    [txtGroup becomeFirstResponder];

    [alertView show];
    alertView = nil;
}
}

Please find the screenshot of Instruments: enter image description here

PK86
  • 1,218
  • 2
  • 14
  • 25

1 Answers1

0

You need to create alertView as :

static UIAlertView *alertView = nil;

if (!alertView){
   alertView = [[UIAlertView alloc] initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
}
KKRocks
  • 8,222
  • 1
  • 18
  • 84