BP.
BP.

Reputation: 10083

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?

Upvotes: 1

Views: 442

Answers (3)

Flash Sheridan
Flash Sheridan

Reputation: 1689

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.

You may no longer care, given John Boker’s answer, but if this was genuinely a problem, you can use an older (or newer) version of the Clang static analyzer by downloading it from http://clang-analyzer.llvm.org/release_notes.html, and telling Xcode to use it with the set-xcode-analyzer command (http://clang-analyzer.llvm.org/xcode.html).

Upvotes: 1

John Boker
John Boker

Reputation: 83709

You should release the picker in the UIImagePickerControllerDelegate callback methods.

Upvotes: 1

UIImagePickerController is autoreleased object presenting that

    UIImagePickerController *cameraUI = [[[UIImagePickerController alloc] init]autorelease];

Upvotes: 0

Related Questions