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..
我同意,除非您有特殊原因,否则您应该不存储对新ViewController的引用。 –
你知道吗,这是我的一个重要监督......我只是将它作为特定函数中的一个实例变量。虽然谢谢! –
所以我改变了我的功能CustomViewController * vc = [[CustomViewController alloc] initWithNibName:@“CustomViewController”bundle:nil]; [[self navigationController] pushViewController:vc]; [vc发布];当它从navigationController中被移除时它仍然没有被释放,这是否意味着在CustomViewController中可能存在一些劣质内存管理? –