【发布时间】:2011-02-19 00:06:03
【问题描述】:
您好,我的 UIViewController(或我创建的任何其他对象)有一个非常基本的内存管理问题; 问题是在 Instruments 中我的对象分配图总是在上升,即使我调用 release 然后将它们分配为零。
我有 2 个 UIViewController 子类,每个子类都使用 NIB 进行初始化;
我将第一个 ViewController 添加到主窗口,例如 [window addSubView:first.view];
然后在我的第一个 ViewController nib 文件中,我有一个加载第二个 ViewController 的按钮,例如:
-(IBAction)loadSecondView{
if(second!=nil){ //second is set as an iVar and @property (nonatomic, retain)ViewController2* second;
[second release];
second=nil;
}
second=[[ViewController2 alloc]initWithNibName:@"ViewController2" bundle:nil];
[self.view addSubView:second.view];
}
在我的(第二个)ViewController2 中,我有一个带有操作方法的按钮
-(IBAction) removeSecond{
[self.view removeFromSuperView];
}
请让我知道上述方案是否以托管方式用于内存...? 在 Instruments 中它不显示任何分配的释放,并保持条形状态图不断上升。
【问题讨论】:
标签: iphone cocoa-touch memory-management memory-leaks uiviewcontroller