我正在使用 LLVM/Clang 静态分析器分析 Objective-C iPhone 项目。我不断收到两个报告的错误,但我很确定代码是正确的。
1) 方便法。
+ (UILabel *)simpleLabel
{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 10, 200, 25)];
label.adjustsFontSizeToFitWidth = YES;
[label autorelease]; // Object with +0 retain counts returned to caller where a +1 (owning) retain count is expected.
return label;
}
2) [NSClassFromString(...) alloc] 返回retainCount + 1。我说的对吗?
Class detailsViewControllerClass =
NSClassFromString(self.detailsViewControllerName);
UIViewController *detailsViewController =
[[detailsViewControllerClass alloc]
performSelector:@selector(initWithAdditive:) withObject:additive];
[self.parentController.navigationController
pushViewController:detailsViewController animated:YES];
[detailsViewController release]; // Incorrect decrement of the reference count of an object is not owned...
这些是一些 Clang 问题还是我在这两种情况下都完全错了?