一部のXMLが一部のURLから解析されている間に、サブビューに追加されるロード画面UIViewを作成しています。XMLが返されると、ロード画面がスーパービューから削除されます。
私が持っている質問は、このオブジェクトをどのようにリリースする必要があるかということです。
以下のコードではremoveFromSuperview
、loadingScreenに送信していることがわかりますが、リリースしない限り、このオブジェクトの所有権は引き続きあります。しかし、私がそれをリリースした場合、リリースするものは何もありませviewdidUnload
んdealloc
。
- (void)loadView {
...
loadingScreen = [[LoadingScreen alloc] initWithFrame: self.view.frame];
[self.view addSubview:loadingScreen]; //retain count = 2
}
-(void)doneParsing {
...
[loadingScreen removeFromSuperview]; //retain count = 1
[loadingScreen release]; //should i release the loading screen here?
}
- (void)viewDidUnload {
[loadingScreen release]; //if viewDidUnload is called AFTER doneParsing, this
//will cause an exception, but the app might crash before
//doneParsing is called, so i need something here
}
- (void)dealloc {
[loadingScreen release]; //if i've already released the object, i can't release here
}