• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Accessor methods and (auto)release: conclusion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessor methods and (auto)release: conclusion


  • Subject: Re: Accessor methods and (auto)release: conclusion
  • From: Ondra Cada <email@hidden>
  • Date: Tue, 6 Aug 2002 15:59:48 +0200

On Tuesday, August 6, 2002, at 03:03 , Marcel Weiher wrote:

I also agree that it is bad practice, because it creates the expectation that certain things 'usually' work...

Well, I fear I have to disagree here. The "invariant" sounds pretty reasonable to me:

"You can depend on the fact that a vended object (from a getter) is valid the whole scope of the current (in the moment the getter was used) autorelease pool".

With the accessors you advocate it DOES NOT HOLD TRUE -- there is a number of situations, often not quite transparent, when the vended object would "magically" disappear under your hands.

That is, unless you hold it: I don't know whether you use -- IMHO pretty ugly -- patterns like

id o=[[[foo getter] retain] autorelease];
... something ...
[o whatever];

or

id o=[[foo getter] retain];
NS_DURING
... something ...
NS_HANDLER
[localException raise];
NS_ENDHANDLER
[o whatever];
[o release];

Unless you do this (do you?), without correct accessors (as I've written) your code is prone to err as soon as ...something... happens to, however indirectly, use the setter or dealloc the foo.

That is not quite robust programming in my vocabulary. I much rather lose a few ticks where I don't need them (ie. in the "return [[ivar retain] autorelease]" getter) than either having to use the ugly patterns shown above next to anywhere, or having always to check in very thorough details the entire ...something... -- whenever the code is changed when maintaining the program -- to be completely sure that its triple hidden sideeffect can't be the setter or foo dealloc!
---
Ondra Hada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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.
  • Follow-Ups:
    • Re: Accessor methods and (auto)release: conclusion
      • From: Marco Scheurer <email@hidden>
    • Re: Accessor methods and (auto)release: conclusion
      • From: Marcel Weiher <email@hidden>
References: 
 >Re: Accessor methods and (auto)release: conclusion (From: Marcel Weiher <email@hidden>)

  • Prev by Date: Re: NSComboBox values don't appear
  • Next by Date: Re: Distributed Objects over a Network
  • Previous by thread: Re: Accessor methods and (auto)release: conclusion
  • Next by thread: Re: Accessor methods and (auto)release: conclusion
  • Index(es):
    • Date
    • Thread