gpt4 book ai didi

iphone - 在两个 View 之间翻转时如何修复 iOS 泄漏

转载 作者:行者123 更新时间:2023-11-29 13:47:41 26 4
gpt4 key购买 nike

在主 uiviewcontroller 和帮助 uiviewcontroller 之间来回切换时,我的 iPhone 应用程序严重泄漏。

这里是主视图的源代码,后面是帮助 View 的源代码。

主视图 - 翻页帮助......................................

// 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];
}

帮助 View - 初始化......................................

- (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;
}

最佳答案

每次调用 showHelp: 时,您正在创建一个引用计数为 1 和本地引用的 Controller :

HelpView *controller = [[HelpView alloc] initWithNibName:@"HelpView" bundle:nil];

您将在此方法结束时丢失对它的引用。

您碰巧在 done:(self)和 *_help_didFinish( Controller )中引用了它,但您从未在这些位置中的任何一个中释放它。关闭 Controller 没问题,但您还必须释放它。

(另一种选择是永远不创建第二个,并保持原始 iVar。)

关于iphone - 在两个 View 之间翻转时如何修复 iOS 泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6625598/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com