Re: Simple instance [[alloc] init] question.
Re: Simple instance [[alloc] init] question.
- Subject: Re: Simple instance [[alloc] init] question.
- From: Kyle Sluder <email@hidden>
- Date: Mon, 30 Aug 2010 23:29:42 -0700
On Aug 30, 2010, at 9:36 PM, Dave Geering <email@hidden> wrote:
>
> I apologise. I was going to explain each one in terms of ownership,
> but I couldn't figure out a way to explain how you own something twice
> without talking about reference counts. I should probably refrain from
> replying to the list any time in the morning.
You might follow the static analyzer's lead and call them "references." For example, +alloc returns a +1 (ownership) reference. You could then talk about gaining another +1 reference through the retain property, and abandoning the one received from +alloc.
Ownership is really a characterization of an object's responsibility, so I find it awkward to talk about it as if it were a token passed rather than a status conferred by said token.
When explaining the memory management rules, though, particularly on the list, sticking to Apple's preferred nomenclature is important for keeping the narrative clear. To be consistent while following the above rubric, I would say "You have violated the memory management rules and created a leak. You became the object's owner through obtaining a +1 reference from +alloc and failed to follow up on your obligation as owner to release the reference. Instead, you have abandoned the initial +1 reference to the void, and created an additional one through the implicit -retain in the property setter."
This has the benefit of being able to point to a state of execution and say "at this point, foo holds a +2 reference to bar." Coworkers who have been in the game much longer are prone to say "foo has a +2 retain count on bar," but for the purposes of this list that might confer unwanted approval on inspection of -retainCount.
Of course, not being an Apple technical writer I don't know if this passes muster with the folks who care the most. ;-)
--Kyle Sluder_______________________________________________
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