3

LLVM/Clang静的アナライザーを使用してObjective-CiPhoneプロジェクトを分析しています。報告されたバグは2つありますが、コードは正しいと確信しています。

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の問題ですか、それとも私はこれらの両方のケースで完全に間違っていますか?

4

1 に答える 1

2

どちらの場合も、コードは正しく見えます。いいえ。performSelector2、プレーンの代わりに使用してアナライザーを混乱させている可能性initWithAdditiveがあります (セレクターを使用している特定の理由はありますか?)。いいえ、よくわかりません。1、ただし、[[[UILabel alloc] init...] autorelease]個別に自動解放する代わりに初期化してみて、問題が解決しないかどうかを確認してください。

于 2010-05-17T13:52:56.603 に答える