开发者

Xcode 4 Analyze does not detect a memory leak situation

开发者 https://www.devze.com 2023-03-18 02:18 出处:网络
I have this code in my iOS app: - (IBAction)cameraButtonPressed:(id)sender { if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO)

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?


You should release the picker in the UIImagePickerControllerDelegate callback methods.


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).


UIImagePickerController is autoreleased object presenting that

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号