XCode的内存配置文件工具无法检测到这种保留周期?

时间:2017-05-26 07:38:14

标签: ios xcode retain-cycle

我做了一个保留周期,但在分析中,这些工具似乎无法找到这种明显的保留周期

首先,ViewController将SubViewController保留为属性subVC,并设置为SubViewController的委托。

@interface ViewController ()<TestDelegate>
@property(nonatomic,strong) UIViewController* subVC;
@end

@implementation ViewController

- (void)dealloc
{
    NSLog(@"ViewController dealloc");
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}


- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    SubViewController* subVC = [[SubViewController alloc] init];
    subVC.delegate = self;
    self.subVC = subVC;
    [self presentViewController:subVC animated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)didSelect
{

}
@end

在SubViewController中,委托被设置为强属性以保留委托

@protocol TestDelegate <NSObject>
@optional
- (void)didSelect;
@end

@interface SubViewController : UIViewController
@property(nonatomic,strong) id<TestDelegate> delegate;
@end

@interface SubViewController ()

@end

@implementation SubViewController

- (void)dealloc
{
    NSLog(@"SubViewController dealloc");
}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

1 个答案:

答案 0 :(得分:0)

好的,现在这些工具似乎只有在我在All Heap&amp; amp;泄漏检查。如果我不切换它们。保留周期永远不会被发现。 enter image description here