gpt4 book ai didi

ios - Dismiss UIViewController 不释放内存

转载 作者:行者123 更新时间:2023-11-29 13:03:39 28 4
gpt4 key购买 nike

我有这个代码

 -(void)didPressButton:(int)tag
{
// Preventivi?
if (tag == 0)
{
if (addPrev == nil)
addPrev = [[avvAddPreventivoViewController alloc] init];
addPrev.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addPrev];
navigationController.navigationBarHidden = NO;
[[navigationController navigationBar] setBarStyle:UIBarStyleBlack];
[self presentViewController:navigationController animated:YES completion:nil];
addPrev = nil;

}
}

当我显示 addPrev 时内存增加,当显示时内存不释放。当 addPrev 关闭时,它会触发协议(protocol)方法 didCancel。我拦截它并释放 addPrev:

  -(void)didCancel
{
[self dismissViewControllerAnimated:YES completion:nil];
addPrev = nil;
}

enter image description here

最佳答案

Niling 还大大改进了导航 Controller 的内存分配。另外,要小心释放你可以在推送 Controller 的 dealloc 中释放的内容。

-(void)didPressButton:(int)tag
{
// Preventivi?
if (tag == 0)
{
if (addPrev == nil)
addPrev = [[avvAddPreventivoViewController alloc] init];
addPrev.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addPrev];
navigationController.navigationBarHidden = NO;
[[navigationController navigationBar] setBarStyle:UIBarStyleBlack];
[self presentViewController:navigationController animated:YES completion:nil];
addPrev = nil;
navigationController = nil;

}
}

关于ios - Dismiss UIViewController 不释放内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19162633/

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