2011-11-03 113 views
0

我想让一个自定义的UIViewController类弹出到导航控制器,然后当弹出的控制器不再被查看时,它是否被释放。但是,视图控制器仍在附近,我不知道为什么。任何帮助,将不胜感激。UIViewController没有被释放

接口:

@property (nonatomic, retain) CustomViewController *viewcontroller; 

实现:

CustomViewController *vc = [[CustomViewController alloc] initWithNibName:@"CustomViewController" bundle:nil]; 

self.CustomViewController = vc; 

[vc release]; // Release this after setting property to avoid memory leak. 

[[self navigationController] pushViewController:[self.CustomViewController autorelease] animated:YES]; 

// Push in the next view. My thinking is that since pushViewController retains this view, if I autorelease when I send the view, the only thing still retaining the view when it shows up will be the navigation controller, and thus when it is bounced back off of the navigation stack, it should be deallocated. But apparently that's not happening.. 

回答

1

你的alloc和init给它保留1计数,去throught的CustomViewController特性赋予了它再次挽留消息,服用2

您需要执行以下操作,在某些时候才能发布....

self.CustomViewController = nil; 

尽管我不确定你为什么是事件存储对它的引用......?!

+0

我同意,除非您有特殊原因,否则您应该不存储对新ViewController的引用。 –

+0

你知道吗,这是我的一个重要监督......我只是将它作为特定函数中的一个实例变量。虽然谢谢! –

+0

所以我改变了我的功能CustomViewController * vc = [[CustomViewController alloc] initWithNibName:@“CustomViewController”bundle:nil]; [[self navigationController] pushViewController:vc]; [vc发布];当它从navigationController中被移除时它仍然没有被释放,这是否意味着在CustomViewController中可能存在一些劣质内存管理? –

相关问题