1

一部のXMLが一部のURLから解析されている間に、サブビューに追加されるロード画面UIViewを作成しています。XMLが返されると、ロード画面がスーパービューから削除されます。

私が持っている質問は、このオブジェクトをどのようにリリースする必要があるかということです。

以下のコードではremoveFromSuperview、loadingScreenに送信していることがわかりますが、リリースしない限り、このオブジェクトの所有権は引き続きあります。しかし、私がそれをリリースした場合、リリースするものは何もありませviewdidUnloaddealloc

- (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
}
4

1 に答える 1

2

LoadingScreenを解放したら、nil値にリセットします。

[loadingScreen release];
loadingScreen = nil;

[リリースなし]は何も起こりません。

于 2010-09-11T14:12:03.760 に答える