[英]release after iPhone navigationController pushViewController
[英]Iphone pushViewController release
當我打電話時:
ChooseDateView *nextController = [[ChooseDateView alloc] initWithNibName:@"ChooseDateView" bundle:nil];
[self.navigationController pushViewController:nextController animated:YES];
是否有必要調用[nextController版本]?
謝謝
是的,有必要打電話
[nextController release]
otherWise使對象作為自動釋放
ChooseDateView *nextController = [[[ChooseDateView alloc] initWithNibName:@"ChooseDateView" bundle:nil] autorelease];
必須調用[nextController release],否則將如何釋放分配的內存?
是。
您只釋放或擁有自己的對象。
如果使用名稱以“ alloc”或“ new”開頭或包含“ copy”(例如alloc,newObject或mutableCopy)的方法創建對象,或者向其發送保留消息,則您擁有該對象的所有權。
您使用釋放或自動釋放來放棄對象的所有權。 自動釋放僅表示“將來發送釋放消息”(要了解何時發送,請參閱“自動釋放池”)。
由於已分配內存,因此您是對象的所有者。 同樣在分配之后,使用pushViewController推送該對象。 這樣我們就可以安全地釋放對象。 因為您擁有該對象,所以必須這樣做。 您也可以自動釋放它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.