On Jul 25, 2013, at 8:20 AM, Matt Neuburg <m...@tidbits.com> wrote:

> Is this the only safe/sensible storage? Could it be an actual object, cast 
> back and forth between id and void*? Could it be stored as an ivar? Thx as 
> always - m.

No, of course, and yes ;-)

Now the static idiom you mentioned is nice in that you don't have to worry 
about it going out of scope just because a function completes and the stack 
frame is destroyed, and because at least the variable itself does not get 
munged. But of course to be useful, MYCONTEXT might have to hold references to 
objects, and then you're back to having to manage the lifetimes of what is 
referred to. Also, it's only good when you only need 1 of the particular 
callback/info combinations to be active, and I find that's an unrealistic 
restriction, and is why I have (IIRC) never used this idiom. Note: I'm 
developing Mac software, so most of my windows/controllers can (and in normal 
use often will) have multiple instances existing at once. (In iOS I expect that 
it would be far more common to have window/controller pairs where there is 
never more than instance in simultaneous existence.)

I think the issue of *what* the context info refers to is far far less 
important than the issue of controlling the contexts (harhar) in which it is 
managed. If you're retaining/releasing them all throughout your code, you're 
asking for trouble. If you alloc an object per callback setup, right where you 
set up the callback, and release it in the callback, you're safe--and that's a 
very common pattern I think.

-- 
Scott Ribe
scott_r...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice





_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to