Re: Telling Auto Save, "No, I'm busy now"
Re: Telling Auto Save, "No, I'm busy now"
- Subject: Re: Telling Auto Save, "No, I'm busy now"
- From: Ken Thomases <email@hidden>
- Date: Thu, 04 Aug 2011 09:53:43 -0500
On Aug 4, 2011, at 8:54 AM, Jerry Krinock wrote:
> I'm getting a crash if I begin some operations and then hit the 'close' button on the window while the operations are in progress…
>
> I take the four parameters I receive in saveToURL:ofType:forSaveOperation:completionHandler: and put them into a dictionary in an NSOperation, and throw this operation onto the end my operation queue. (This project was written back in 10.5 so it does not use GCD.)
Did you copy the block, or did you just add it to the dictionary as a value (which just retains it)? You need to copy it and then later release it.
> When this final operation runs, I send this dictionary to a selector on the main thread. But the completion handler seems to contain a bomb at this point – it usually crashes upon receiving any message, not always in the same place. Often, it crashes when I send it to super's saveToURL:ofType:forSaveOperation:completionHandler:, which apparently tries to copy it, like this…
>
> #0 0x97c68987 in _Block_copy_internal
> #1 0x97c68bd8 in _Block_object_assign
> #2 0x97123a41 in __copy_helper_block_138
> #3 0x97c67f86 in _Block_call_copy_helper
> #4 0x97c689d3 in _Block_copy_internal
> #5 0x97c68bd8 in _Block_object_assign
> #6 0x9713f43b in __copy_helper_block_40
> #7 0x97c67f86 in _Block_call_copy_helper
> #8 0x97c689d3 in _Block_copy_internal
> #9 0x9bb22eae in _dispatch_Block_copy
> #10 0x9bb251ea in dispatch_async
> #11 0x9713ac9c in -[NSDocument performAsynchronousFileAccessUsingBlock:]
> #12 0x97123688 in -[NSDocument saveToURL:ofType:forSaveOperation:completionHandler:]
This suggests that you didn't copy it. Thus, the above is the first time it has been copied, which attempts to relocated it off of its original stack frame and into the heap. However, that stack frame is long gone and no longer valid.
> Retaining the completionHandler a half dozen times, with no corresponding releases, before placing into the dictionary, does not help. So apparently it's not memory management.
Blocks have special memory management requirements and retaining is not sufficient if the block is to survive its original stack frame.
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden