我創建一個新的UIViewController與下面的代碼的UIViewController保留計數問題
GameViewController *temp = [[GameViewController alloc] initWithNibName:@"GameViewController" bundle:nil];
NSLog(@"retain count%d", [temp retainCount]);
temp.backgroundMusic = backgroundMusic;
self.gameView = temp;
[temp release];
[self presentModalViewController:gameView animated:YES];
[gameView release];
,但是當我看到保留計數,我臨時視圖控制器返回4
這怎麼可能?因爲它是4,所以當我解僱視圖控制器時,我無法將它從內存中移除,並且我的遊戲正在播放。 (我可以看到AI玩的效果)。
[gameView release] should be self.gameView = nil; (具體取決於你是否用保留聲明瞭gameView屬性) –