ここで何が起こっているのかわかりませんが、initメソッドに次のコードがあります。
NSLog(@"retain count in init before alloc: %d", [game1CustomEntityInfoControl retainCount]);
game1CustomEntityInfoControl = [[CustomEntityInfoControl alloc] initWithFrame:CGRectZero];
NSLog(@"retain count in init after alloc: %d", [game1CustomEntityInfoControl retainCount]);
[[self contentView] addSubview:game1CustomEntityInfoControl];
NSLog(@"retain count in init after adding to superview: %d", [game1CustomEntityInfoControl retainCount]);
スーパービューはオブジェクトを保持しているので、game1CustomEntityInfoControlをリリースする必要があることはわかっていますが、今はそのままにしておきます。
次に、layoutSubviewsメソッドに次のようになります。
// We always call this, the table view cell needs to do its own work first
[super layoutSubviews];
NSLog(@"retain count as soon as you enter layoutSubviews: %d", [game1CustomEntityInfoControl retainCount]);
[[self contentView] subviews];
NSLog(@"retain count in layoutSubviews after calling subviews on contentView: %d", [game1CustomEntityInfoControl retainCount]);
これは出力です:
2010-10-24 15:14:08.598算額[8592:207]割り当て前の初期化でカウントを保持:0
2010-10-24 15:14:08.603算額[8592:207]割り当て後の初期化でカウントを保持:1
2010-10-24 15:14:08.611算額[8592:207]スーパービューに追加した後、初期化でカウントを保持:2
2010-10-24 15:14:08.616算額[8592:207]レイアウトに入るとすぐにカウントを保持サブビュー:2
2010-10-24 15:14:08.621 Sangaku [8592:207] contentViewでサブビューを呼び出した後、layoutSubviewsのカウントを保持します:3
出力の最後の行を見てください。保持カウントはどのようにして3になりましたか?サブビューは、自動解放として返される割り当てを内部的に実行しますか?
ありがとう