-(IBAction)startGameButtonClicked:(id)sender{
//gameViewController = NULL;
//[gameViewController release];
//[gameViewController dealloc];
if(!gameViewController){
gameViewController = [[GameViewController alloc] initWithNibName:@"GameViewController" bundle:nil];
}
appDelegate.ScoreID=0;
[gameViewController resetLevel];
[gameViewController resetTheGame];
[self.navigationController pushViewController:gameViewController animated:YES];
} <---Says the leak is here
1
A
回答
1
每次單擊按鈕時,都會創建一個新的gameViewController並將其推入self.navigationController。
你不想每次都做一個新的。
+0
我該怎麼做? – Steve 2010-02-03 22:44:54
+0
使'gameViewController'成爲具有屬性的ivar(實例變量)並將其作爲'self.gameViewController'引用。 – 2010-02-03 23:47:46
2
分配
self.gameViewController = [[GameViewController alloc] initWithNibName:@"GameViewController" bundle:nil];
,並在釋放時設立gameViewController作爲屬性在.H
@property(nonatomic,retain) GameViewController *gameViewController;
,並在.M
@synthesize gameViewController
然後使用屬性end
[self.navigationController pushViewController:gameViewController animated:YES];
[gameViewController release];
相關問題
- 1. 這裏的泄漏在哪裏?
- 2. 這裏的泄漏在哪裏?
- 3. 泄漏在哪裏?
- 4. 泄漏在哪裏?
- 5. Objective-C - 泄漏在哪裏?
- 6. 內存泄漏在哪裏
- 7. 內存泄漏在哪裏?
- 8. 內存泄漏在哪裏?
- 9. 熊貓:這裏的內存在哪裏泄漏?
- 10. 內存泄漏,但哪裏?
- 11. 哪裏是內存泄漏
- 12. GLKShaderBlockNode泄漏來自哪裏?
- 13. BlogEntry上的內存泄漏在哪裏?
- 14. 我的內存泄漏在哪裏?
- 15. 我的代碼在哪裏泄漏?
- 16. 我的內存泄漏在哪裏?
- 17. 哪裏是在該C內存泄漏++?
- 18. C++內存泄漏,在哪裏?
- 19. 內存泄漏它在哪裏
- 20. iphone圖像泄漏,但在哪裏?
- 21. 這個PHP代碼片段中的內存泄漏在哪裏?
- 22. 這個函數的內存泄漏在哪裏?
- 23. 這個泄漏在哪裏? /爲什麼我有內存問題?
- 24. 這裏有沒有內存泄漏?
- 25. 這裏的js在哪裏
- 26. 我在這個Doctrine 1.2代碼中的內存泄漏在哪裏?
- 27. 我的NSXMLParser代碼中的泄漏在哪裏?
- 28. 我的iPhone應用程序中的內存泄漏在哪裏?
- 29. JavaScript/jQuery中的內存泄漏在哪裏?
- 30. 以下代碼中的服務泄漏在哪裏?
稍後您會發布gameViewController嗎? 並且resetLevel和resetTheGame方法是否乾淨? – 2010-02-03 23:15:15