Search code examples
ios4xcode4static-analysisclang-static-analyzer

Xcode 4 Analyze does not detect a memory leak situation


I have this code in my iOS app:

- (IBAction)cameraButtonPressed:(id)sender
{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO)
    {
        return;
    }

    UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
    cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
    cameraUI.allowsEditing = NO;
    cameraUI.delegate = self;
    [self presentModalViewController:cameraUI animated:YES];
}

The problem with this code is that there needs to be a [cameraUI release]; at the end of the method. In the past, the static code analyzer built into Xcode has helped me catch these oversights, but with my current Xcode 4.0.2 install, it does not find this problem. I have tried to restart Xcode, and tried the Clean Build Folder (holding down option while clicking the Project menu), and have had no luck. Is there a problem with the analyzer in the newest Xcode, or is there something else I am missing?


Solution

  • You should release the picker in the UIImagePickerControllerDelegate callback methods.