Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone iOS-在ARC下弹出时未释放ViewController_Iphone_Ios_Memory Management_Automatic Ref Counting - Fatal编程技术网

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

Iphone iOS-在ARC下弹出时未释放ViewController,iphone,ios,memory-management,automatic-ref-counting,Iphone,Ios,Memory Management,Automatic Ref Counting,我有一个UITabBarController作为我的主基本视图控制器。在第一个选项卡下,我有一个UINavigationController,它当然有一个与之关联的rootViewController,称之为vcAvcA有一个按钮,使用以下代码触发子视图控制器,vcB: [self performSegueWithIdentifier:@"PlacesDetailsSegue" sender:senderDictionary]; __unsafe_unretained BBCategoryVi

我有一个
UITabBarController
作为我的主基本视图控制器。在第一个选项卡下,我有一个
UINavigationController
,它当然有一个与之关联的
rootViewController
,称之为
vcA
vcA
有一个按钮,使用以下代码触发子视图控制器,
vcB

[self performSegueWithIdentifier:@"PlacesDetailsSegue" sender:senderDictionary];
__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的新分配正在发生。 当我将视图控制器弹出回
vcA
时,一切看起来都正常,但vcB似乎从未释放(即从未调用dealloc)。因此,每次从
vcA->vcB->vcA->vcB
开始,内存使用量都会不断增加

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

我确实有一个
[UIView animationWith…]
块,它引用了
self.view
的帧属性,但我使用代码管理了它:

[self performSegueWithIdentifier:@"PlacesDetailsSegue" sender:senderDictionary];
__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 BBCategoryViewController () <UITableViewDataSource, UITableViewDelegate> {
    UITableView *_feedTableView;
    UIRefreshControl *_refreshControl;
    BBSearchBar *_searchBar;
    MKMapView *_mapView;
    BBNavigationBar *_navBar;
    NSString *_title;
    NSString *_categoryId;
    NSArray *_feedArray;
}
@end

更新:这实际上是由于子视图中存在一个保留周期,而不像我第一次想到的那样与视图控制器直接相关。Dan F引导我找到了正确的答案,以防有人遇到类似的情况。

您的vcB绝对应该被解除分配,当您返回vcA时,dealloc会打电话给您。你必须在某个地方保留对它的强烈引用,否则你的“pop”做得不对。如果你用一个segue来做这件事,那可能是你的问题——segue不应该用于倒退(除了放松segue)。因此,要么使用“展开”序列,要么使用popViewControllerAnimated返回vcA。此外,在使用ARC时,无需在dealloc中将ivars设置为零。

您真的看到了这种行为吗?每次执行segue时都会实例化视图控制器?@DanF:我在instruments中看到分配,是的。你是如何“弹出”到vcA的?你用的是segue吗?你有一个参考周期。可能是一个街区。我们几周前也遇到过类似的问题;我们怀疑存在一个很强的保留周期,因为在我们从导航堆栈中弹出视图控制器之后,内存没有被释放。最后,我们发现,当应用程序刚刚运行时,iOS不会立即释放视图控制器的内存,但当我们将应用程序放到后台时,iOS立即正确释放了内存。我想你已经了解了一些事情。vcB中的某些内容正在强制使用强引用。有什么工具可以帮助你弄清楚它是什么吗?我正在使用
popViewControllerAnimated
弹出视图。@Brett,我不知道有什么工具可以这样做。你的代码是如此复杂以至于你无法通过检查找到它吗?您是否在这两个类之间使用代理协议?