Re: Blocks vs. life, the universe and everything
Re: Blocks vs. life, the universe and everything
- Subject: Re: Blocks vs. life, the universe and everything
- From: Greg Parker <email@hidden>
- Date: Fri, 14 Oct 2011 14:27:06 -0700
On Oct 14, 2011, at 1:56 PM, Quincey Morris wrote:
> The problem is that the documentation clearly states that exceptions must not try to escape across dispatch queue operation boundaries. AFAICT, this means that for every one of the tiny code block fragments I write, not only does my fragment need to be wrapped in a '@try' block, I must also deal with the exception by (say) logging its description before leaving the block. Every time. That seems like an awful lot of boilerplate code, and it makes the blocks-based approach very unpalatable.
Do you actually use exceptions in your code, or do you follow the Cocoa convention that exceptions are for programmer error only? If you don't use exceptions, then you can omit any try blocks and let the uncaught exception handler log the failure and kill the process.
> Secondarily, I can find nothing in any GCD-related documentation that addresses the proper use of autorelease pools in dispatched blocks. I'm *guessing* that I need to set up my own. That's much less onerous that handling exceptions (a simple @autoreleasepool wrapper), and I guess there's no real downside in creating my own pool even if unnecessary, but I still wish I knew what I was *supposed* to do.
From the Concurrency Programming Guide:
"If your block creates more than a few Objective-C objects, you might want to create your own autorelease pool to handle the memory management for those objects. Although GCD dispatch queues have their own autorelease pools, they make no guarantees as to when those pools are drained. However, if your application is memory constrained, creating your own autorelease pool allows you to free up the memory for autoreleased objects at more regular intervals."
Currently, a dispatch-provided autorelease pool is not drained until the dispatch worker thread goes idle. If you keep a dispatch queue continuously busy with dispatch work that generates autorelease pool garbage, then you might run into trouble.
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
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