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 (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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com