我做了一个保留周期,但在分析中,这些工具似乎无法找到这种明显的保留周期
首先,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