私は、Objective-C 開発を学び始めた経験豊富な C/C++ プログラマーです。現在、UICatalog サンプルを調べていると、いくつかの場所で見たが理解できなかったイディオムの別のインスタンスに出くわしました。
コード:
ButtonsViewController *buttonsViewController = [[ButtonsViewController alloc] initWithNibName:@"ButtonsViewController" bundle:nil];
[self.menuList addObject:[NSDictionary dictionaryWithObjectsAndKeys:
NSLocalizedString(@"ButtonsTitle", @""), kTitleKey,
NSLocalizedString(@"ButtonsExplain", @""), kExplainKey,
buttonsViewController, kViewControllerKey, nil]];
[buttonsViewController release];
私の知る限り、これは ButtonsViewController を割り当てて初期化し、ButtonsViewController の NSDictionary を作成し、辞書を menuList と呼ばれる NSMutableArray に追加します (これは上記のコードが存在する MainViewController のメンバー変数です)。その後、必要に応じて MainViewController がディクショナリ エントリを使用してビューを buttonsViewController に切り替えます。
私の質問は: なぜこのコードの後でも buttonsViewController がまだ有効なのですか? 間に「保持」なしで割り当てられ、解放されました。NSDictionary または NSMutableArray に何かを追加すると、暗黙の「保持」がありますか? もしそうなら、私はそれをどうにかして理解できるはずだったのですか、それともあなたが読んで覚えなければならないことの1つにすぎませんか?