I have aUITabBarController
作为我的主要基础视图控制器。在第一个选项卡下,我有一个UINavigationController
这当然有一个rootViewController
与它相关联,称之为vcA
. vcA
有一个触发子视图控制器的按钮,vcB
使用代码:
[self performSegueWithIdentifier:@"PlacesDetailsSegue" sender:senderDictionary];
这似乎有效,并且我在工具中看到 vcB 的新分配正在发生。
当我将视图控制器弹回到vcA
,一切看起来都正常,但 vcB 似乎从未被释放(即,dealloc 从未被调用)。所以每次从vcA->vcB->vcA->vcB
,内存使用量不断增加。
我里面有一些实例变量vcB
,所有这些我都设置为nil
in dealloc
。但由于 dealloc 没有被解雇,所以它们实际上从未被设置为nil
.
我确实有一个[UIView animationWith...]
引用框架属性的块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 弹出窗口中仍保留哪些对象?
作为参考,我的接口扩展是:
@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;
}
UPDATE:这实际上是由于子视图中的保留周期造成的,而不是像我首先想到的那样与视图控制器直接相关。 Dan F 引导我找到了正确答案here https://stackoverflow.com/questions/18387476/passing-a-viewcontroller-to-a-child-view-and-then-back-again-fails-to-release-t,以防有人遇到类似的事情。