iOS – Is this a reserved cycle?

When I call myself in a reserved block, I usually get a warning:

 [self.someView doSomething:^{
self.aVar = @"Hello!";
}];

I will do:

__weak SomeObject *weakSelf = self;
[self.someView doSomething:^{
weakSelf.aVar = @"Hello!";
}];

But if I call a method on weakSelf, and the method uses self, even if I don’t get a warning, will this cause a retention period? I’m talking about this:

__weak SomeObject *weakSelf = self;
[self.someView doSomething:^{
weakSelf.aVar = @"Hello! ";
[weakSelf aMethod];
}];

Use self with aMethod

As long as your weakSelf is declared outside your block, there is no retention period.

Using objects in the block will implicitly increase the retention count. But you have to Call a method on weakSelf instead of self, so the reserved count is not affected.

When I call myself in a block reserved by myself, I usually receive To the warning:

[self.someView doSomething:^{
self.aVar = @"Hello!";
}];< /pre>

I will do:

__weak SomeObject *weakSelf = self;
[self.someView doSomething:^{
weakSelf.aVar = @"Hello!";
}];

But if I call a method on weakSelf, and the method uses self, even if I don’t get a warning, will this cause a retention cycle? ? I'm talking about this:

__weak SomeObject *weakSelf = self;
[self.someView doSomething:^{
weakSelf.aVar = @"Hello! ";
[weakSelf aMethod];
}];

Use self with aMethod

As long as your weakSelf is declared outside your block, there is no retention period.

Using objects in the block will implicitly increase the retention count. But you have to call a method on weakSelf instead of self, so the retention count Not affected.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3915 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.