Xcode 4 Analytics 未检测到内存泄漏情况
我的 iOS 应用程序中有这段代码:
- (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];
}
这段代码的问题是方法末尾需要有一个 [cameraUI release];
。过去,Xcode 内置的静态代码分析器帮助我发现了这些疏忽,但在我当前安装的 Xcode 4.0.2 中,它没有发现这个问题。我尝试重新启动 Xcode,并尝试清理构建文件夹(在单击“项目”菜单时按住选项),但没有成功。最新的 Xcode 中的分析器是否有问题,或者我还遗漏了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该在
UIImagePickerControllerDelegate
回调方法中释放picker
。You should release the
picker
in theUIImagePickerControllerDelegate
callback methods.鉴于 John Boker 的回答,您可能不再关心,但如果这确实是一个问题,您可以通过从 http://clang-analyzer.llvm.org/release_notes.html,并告诉 Xcode 将其与
set-xcode-analyzer
命令(http://clang-analyzer.llvm .org/xcode.html)。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 是自动释放的对象, UIImagePickerController *cameraUI = [[[UIImagePickerController alloc] init]autorelease];
UIImagePickerController is autoreleased object presenting that
UIImagePickerController *cameraUI = [[[UIImagePickerController alloc] init]autorelease];