Re: Problem using bindings with deep key paths
Re: Problem using bindings with deep key paths
- Subject: Re: Problem using bindings with deep key paths
- From: Gwynne Raskind <email@hidden>
- Date: Wed, 20 Jan 2010 21:18:33 -0500
On Jan 20, 2010, at 6:05 PM, Quincey Morris wrote:
>>> (Though it vaguely annoys me that I have to add a spurious retain/autorelease to the Player object.)
>> You don't technically have to. You could do:
>>
>> [self willChangeValueForKey:@"player"];
>> player = [[Player alloc] init];
>> [self didChangeValueForKey:@"player"];
> ... which is unexceptionable, but another alternative might be:
>
> Player* aPlayer = [[Player alloc] init];
> self.player = aPlayer;
> [aPlayer release];
>
> although (given a couple of contemporaneous threads on the subject of autorelease and its subtleties, and given that I'm sitting smugly on the GC side of the fence) I wouldn't be surprised to find out that the latter suggestion sucks.
I've gotten the idea (mostly from this list and objc-language) that GC is fraught with all manner of peril, and since my coding style is pedantic enough to keep me from most retain/release management mistakes (with the help of Clang's analyzer), I stick to what I know :). All three options are ugly in their own ways. In this specific case, since the Player object never changes, I could make the property assign instead of retain and manually release it in -dealloc, but I consider that equally ugly since it's conceptually incorrect (I'd be declaring the Player to be a weak reference when it isn't).
-- Gwynne
_______________________________________________
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