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