When is the autorelease object released?


When is the autorelease object released?
I tested it with the following code,and I found that the autorelease objc never release.
```
__weak id ref;
@implementation ViewController
- (void)viewDidLoad
[super viewDidLoad];
NSString *str = [NSString stringWithFormat:@"test"]; // add autoreleasePool
ref = str;
- (void)viewWillAppear:(BOOL)animated
[super viewWillAppear:animated];
NSLog(@"viewWillAppear:%@",ref); // result test
- (void)viewDidAppear:(BOOL)animated
[super viewDidAppear:animated];
NSLog(@"viewDidAppear:%@",ref); // result test
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
NSLog(@"%@",ref); // If I click long after,But it has not been released
```
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Comments
Post a Comment