我的iPhone應用程序中有RootViewController和DetailsViewController。我使用Allocations工具來監視我的內存消耗,並且我有一個問題。我的應用程序啓動時需要大約4Mb的內存,當我在RootViewController中選擇項目時,它會在DetailsViewController中加載UIWebView並且內存上升到10Mb,在我返回RootViewController內存後保持在10Mb級別,DetailsViewController的內存爲retainCount = 2
(即使我只創建一次)。何時發佈detailsViewController
我該如何釋放這些內存?我知道我應該這樣做,如果我的應用程序收到內存警告,但我使用initWithNibName:
創建此ViewController,所以我明白我不應該發送release
它。
謝謝。
編輯
我加載它是這樣的:
if (self.detailsViewController == nil)
{
detailsViewController *d = [[detailsViewController alloc]
initWithNibName:@"DetailsViewController"
bundle:[NSBundle mainBundle]];
self.detailsViewController = d;
[d release];
self.detailsViewController.urlToLoad = urlToLoad;
}
[self.navigationController pushViewController: self.detailsViewController animated:YES];
DetailsViewController應該有一個retainCount爲1,因爲它是一個新對象,你如何加載這個Nib? – 2010-08-26 12:01:53
如果detailsViewController屬性聲明爲retain(我認爲是),那麼你需要釋放它,可能在dealloc中。 – taskinoor 2010-08-26 13:07:44
請參閱下面的答案。按下後應該釋放控制器。 – tobiasbayer 2010-08-26 13:17:54