我的iPhone应用程序在主uiviewcontroller和帮助uiviewcontroller之间来回切换时严重泄漏。
以下是主视图的来源,后面是帮助视图的来源。
主要观点 - 提供帮助.....................
// Changes from operational view to Help view.
- (IBAction)showHelp:(id)sender
{
// End trial mode:
self.stop_trial_if_started;
self.rename_trial_if_edited;
// Switch to trial help:
help_view_context = 0;
HelpView *controller = [[HelpView alloc] initWithNibName:@"HelpView" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
帮助视图 - INIT .............................
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
help_scroll.editable = FALSE;
return;
}
帮助 - 返回主视图.........................
// User clicked the button to return to operational view:
- (IBAction)done:(id)sender {
NSLog(@"help- done");
if( help_view_context == 0 ) {
[self.delegate trial_help_DidFinish:self];
}else{
[self.delegate file_help_DidFinish:self];
}
}
主要观点 - 从帮助中退回................................
// Inits operational view when user changes from Help view back to operational view.
- (void)trial_help_DidFinish:(HelpView *)controller {
NSLog(@"trial_help_DidFinish");
[self dismissModalViewControllerAnimated:YES];
self.init_trial_operation;
}
答案 0 :(得分:1)
每次调用showHelp:
时,您正在创建一个ref count为1的控制器和一个本地引用:
HelpView *controller = [[HelpView alloc] initWithNibName:@"HelpView" bundle:nil];
在此方法结束时,您将失去对它的引用。
您恰好在done:
(自我)和*_help_didFinish
(控制器)中引用了它,但您从未在其中任何一个位置发布过它。解雇控制器很好,但你还必须release
。
(另一种选择是永远不要创建第二个,并将iVar维持在原始状态。)
答案 1 :(得分:0)
你可能会在这条线上泄漏
controller.delegate = self;
代表的财产声明是什么?如果它不是assign,那么你需要更改它(首选选项)或确保你在dealloc
控制器的HelpView
方法中释放它。