Re: Memory management of document modal panels
On Jul 25, 2017, at 22:41 , Graham Cox <graham@...> wrote:
Hmm. I just realized I forgot this was MM not ARC. In that case, I don’t know if the block retains “self” automatically at all. It shouldn’t, since it’s MR, but it’s possible that it handles “self” or captured variables specially, and retains it anyway.
The block is copied from the stack to the heap (making it a reference counted object) before it’s passed as a parameter to the called method. (In Swift, there’s a distinction between a block parameter whose lifetime ends at the return from the method, and one whose lifetime may “escape” that restriction, but AFAIK everything is regarded as “escaping” in Obj-C if the block is passed out of the scope.)
If the block does retain any of its references in MM, then it would do it when the block is copied. The captured variables have to go on the heap if the block escapes the current scope. Conceptually, that would be at the top of the block scope.
But I don’t really know the rules for blocks and MM. That scenario is one historical generation older than even the stuff I want to forget. ;)