Re: Accessor methods and (auto)release <Memory trail>
Re: Accessor methods and (auto)release <Memory trail>
- Subject: Re: Accessor methods and (auto)release <Memory trail>
- From: Marcel Weiher <email@hidden>
- Date: Sun, 4 Aug 2002 14:47:43 +0200
On Friday, August 2, 2002, at 06:10 Uhr, Ali Ozer wrote:
So, is the above pattern (getter which retains and autoreleases) used
in Cocoa at all? Or, is it just a theoretically correct, but
practically for diverse reasons never (or extremely rarely) used one?
Good question... You're right that not many classes that can use this
technique do right now.
As mentioned before, a few low-level classes (such as the collections,
attributed string, etc) don't and won't use this technique because
they are collections and don't want to fiddle with the lifetime of
your objects.
Many other classes use other techniques, mostly due to the fact their
set/get methods were written many years ago when we were still
enumerating the techniques, still looking at the performance
characteristics, and not as much aware of thread safety issues. We
have actually fixed some cases in Jaguar to use this exact technique,
and will probably continue to do so as long as we don't introduce any
serious binary incompatibilities (which is unfortunately a serious
threat)...
But, I believe that especially for people just approaching Cocoa and
for anyone writing new classes, this get/set pattern is the most
appropriate unless there are significant performance concerns like
"getter will be called a lot".
While I can see your reasoning, I have to admit I feel very
uncomfortable with it. I can also bring some reasons why, but can't
say if those actually cover it.
1. I think your point about collections not fiddling with the lifetime
of objects applies to all *accessors*.
2. This pattern seems more suitable for methods that 'appear' to be
returning a newly constructed object but in fact return an existing one.
3. Autorelease adds not just a performance penalty, but also a
complexity penalty. I am not sure adding it in more or less
gratuitously is a good idea, especially for newbies. Simplicity and
predictability are important.
4. It seems to me that adding the autorelease could easily gloss over
real problems, and actually make them even harder to find.
Marcel
--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.