【问题标题】:pushViewController causes memory leakpushViewController 导致内存泄漏
【发布时间】:2011-02-01 15:32:54
【问题描述】:

Leaks 应用程序告诉我以下函数导致内存泄漏,我不知道为什么。

-(void)viewGameList {
GameListController *gameListViewController = [[GameListController alloc] initWithNibName:@"GameListController" bundle:nil];
gameListViewController.rootController = self;
[self.navigationController pushViewController:gameListViewController animated:YES];
[gameListViewController release];

}

它告诉我这一行会导致 128 字节的内存泄漏。

[self.navigationController pushViewController:gameListViewController animated:YES];

我是否遗漏了一些明显的东西?

【问题讨论】:

  • 属性.rootController是如何声明的?
  • 我不确定代码是否会在评论中正确显示,但这是 GameListController.m 对您问题的回答:@class RootViewController; @interface GameListController : UIViewController { RootViewController *rootController; @property (nonatomic, 保留) RootViewController *rootController;关于为什么我会在这里出现内存泄漏的任何想法?

标签: iphone memory-leaks uinavigationcontroller


【解决方案1】:

关于 iPhone 内存管理的一条规则。

  • 子对象绝不能保留其父对象。

所以,不要在属性声明中使用 retain,而是使用 assign

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-06
    • 2014-06-07
    • 2013-11-20
    • 2011-10-28
    • 2016-01-18
    • 2012-12-13
    相关资源
    最近更新 更多