gpt4 book ai didi

iphone - iOS - 在 ARC 下弹出时 ViewController 未被释放

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:20:53 26 4
gpt4 key购买 nike

我有一个UITabBarController 作为我的主要基础 View Controller 。在第一个选项卡下,我有一个 UINavigationController,它当然有一个与之相关联的 rootViewController,称之为 vcAvcA 有一个按钮可以触发 subview Controller ,vcB 使用代码:

[self performSegueWithIdentifier:@"PlacesDetailsSegue" sender:senderDictionary];

这似乎有效,我在仪器中看到 vcB 的新分配正在发生。当我将 View Controller 弹回到 vcA 时,一切看起来都正常,但似乎从未释放过 vcB(即从未调用过 dealloc)。因此,每次从 vcA->vcB->vcA->vcB 开始,内存使用量都会越来越大。

我在 vcB 中有一些实例变量,所有这些我都在 dealloc 中设置为 nil。但由于没有触发 dealloc,因此它们实际上从未设置为 nil

我确实有一个 [UIView animationWith...] block 引用了 self.view 的框架属性,但我已经使用代码管理了它:

__unsafe_unretained BBCategoryViewController *weakSelf = self;

[UIView animateWithDuration:duration
animations:^{
[_feedTableView setFrame:CGRectMake(0,
_navBar.frame.size.height,
weakSelf.view.frame.size.width,
weakSelf.view.frame.size.height - kMenuBarHeight)
];

}
completion:nil];

有谁知道我如何才能找出哪些对象仍保留在 vcB pop 上?

作为引用,我的接口(interface)扩展是:

@interface BBCategoryViewController () <UITableViewDataSource, UITableViewDelegate> {
UITableView *_feedTableView;
UIRefreshControl *_refreshControl;
BBSearchBar *_searchBar;
MKMapView *_mapView;
BBNavigationBar *_navBar;
NSString *_title;
NSString *_categoryId;
NSArray *_feedArray;
}
@end

我的 dealloc(永远不会被解雇)是:

-(void)dealloc {

NSLog(@"Dealloc: BBCategoryViewController\n");
_feedTableView = nil;
_refreshControl = nil;
_searchBar = nil;
_mapView = nil;
_navBar = nil;
_feedArray = nil;

}

更新:这实际上是由于 subview 中的保留循环,而不是像我最初认为的那样与 View Controller 直接相关。 Dan F 让我找到了正确答案 here ,以防万一有人遇到类似的事情。

最佳答案

你的 vcB 绝对应该被释放,当你弹回 vcA 时 dealloc 被调用。您必须在某处保持对它的强烈引用,或者您正在错误地进行“流行”。如果您使用 segue 执行此操作,那可能是您的问题——segue 不应用于向后移动(unwind segue 除外)。因此,要么使用 unwind segue,要么使用 popViewControllerAnimated 返回到 vcA。此外,使用 ARC 时,无需在 dealloc 中将 ivars 设置为 nil。

关于iphone - iOS - 在 ARC 下弹出时 ViewController 未被释放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18381236/

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