Answer the question
In order to leave comments, you need to log in
What does Capturing 'self' strongly in this block is likely to lead to a retain cycle mean?
Good afternoon!
The compiler issues the following warning:
Capturing 'self' strongly in this block is likely to lead to a retain
cycle
_autocompleteViewDestination.didAutocompleteWith = ^(id item) {
NSLog(@"Autocompleted with: %@", item.completionText);
[self.session saveDestinationPointWith:item.completionText andLocation:item.location]; <<<
};
Answer the question
In order to leave comments, you need to log in
The compiler tells you that you have a link to the block, and the block has a link to you. As a result, APC will not be able to delete these two objects and they will be forever in memory. Which eventually leads to a memory leak.
You can fight:
1) Removing the link to the block if it is not critical, or making it weak
2) Pass yourself to the block by a weak link:
__weak MyClass *me = self;
... = ^() {
[me.session ...];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question