【发布时间】:2009-08-06 13:48:35
【问题描述】:
当我调用另一个控制器时,我的 UIViewController 是否被释放? 当我推送到另一个控制器时如何释放控制器的内存?由于内存不足(无泄漏),我需要超过 40 个月和申请休假。
[self.navigationController pushViewController:[[MainListController alloc] init:self] animated:NO];
@interface MainListController : UIViewController
...
- (id)init: (id)ref;
当我调用init函数时,控制器的dealloc是:
[ref dealloc];
我有这个错误:
objc[70754]: FREED(id): message isEqual: sent to freed object=0xe216b0
Program received signal: “EXC_BAD_INSTRUCTION”.
- (void)dealloc {[super dealloc];}
【问题讨论】:
-
@Nicolas:您在上面发布的这段代码绝对是泄漏的。 navigationController 保留了您的控制器,您正在创建它而不在那里自动释放它。每次以这种方式推动控制器时,您都会绝对泄漏。您必须执行以下操作: [self.navigationController pushViewController:[[[MainListController alloc] init:self] autorelease] animated:NO];
-
另外,请确保您在视图控制器的 init:self 调用中的代码不会保留您传递给它的变量,否则您将有一个保留周期,具体取决于此导航控制器的方式/位置已创建,也可能会泄漏。
-
我不会失去记忆,因为我再也没有回到这个控制器,这就是我想要释放它的原因!你有其他解决方案吗?
-
是:MainListController* mlc = [[MainListController alloc] init:self]; [self.navigationController pushViewController:mlc Animation:NO]; [mlc 发布]; ——本该如此。导航控制器将在不再需要时释放它。
标签: iphone cocoa-touch xcode