On Fri, Dec 26, 2008 at 1:18 PM, Robert Marini <r...@pinchmedia.com> wrote:
>> I have never wrapped any methods in retain/release calls as you
>> described. I've never seen code that does it, and I've never even
>> *heard* of anyone doing it until now. Ask yourself this: do you do
>> [self retain] at the beginning of a method and [self release] at the
>> end? If not, why not? Self is just a parameter like any other. It gets
>> no special treatment (aside from being used to make decisions during
>> the dispatch process). If what you're saying is correct, you must also
>> do [self retain] and [self release] at the beginning and end of every
>> single method you ever write. I hope that this is self-evidently
>> absurd.
>
> As I mentioned above, if one cannot distinguish whether an object is
> autoreleased or not and one is using mailing lists as an alternative to
> documentation and/or real debugging then one is perhaps best served by the
> most defensive code possible such that the flow of logic in the
> application's architecture is clear and the details of memory management
> optimizations are left as an exercise for later. As the frameworks progress,
> memory management is quickly becoming an anachronistic chapter in the long
> life of Cocoa and in four years I do not expect that we'll be having this
> discussion.

Retaining method parameters at the top of the method and releasing
them at the bottom is not "defensive code". It is, perhaps, "pointless
code", or "stupid code", or "code that indicates someone doesn't
understand what's going on". It is not a useful thing to do in any
way.

Do you retain and release self in this manner, or not? If not, why
not? As I said, for consistency, you should be doing it to self as
well as your other parameters as it gets treated *exactly* the same
way.

If you get a parameter passed into your method then it will remain
valid for the lifetime of that method unless you explicitly take an
action to destroy it or the code which invokes you is extremely poorly
written. In the case where the calling code is poorly written,
retaining your arguments *does not actually help*, so it's a useless
gesture either way.

It can be useful to retain objects to guard against a subsequent
setter destroying them, although this is a very rare problem. But that
is not even remotely close to what you claimed in your original
message. That whole business about other threads destroying your
objects while you're using them simply makes no sense whatsoever.

Mike
_______________________________________________

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

Reply via email to