• 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: [[object autorelease] release]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [[object autorelease] release]


  • Subject: Re: [[object autorelease] release]
  • From: "John C. Randolph" <email@hidden>
  • Date: Mon, 1 Oct 2001 17:20:06 -0700

On Monday, October 1, 2001, at 04:26 PM, Ondra Cada wrote:

John,

John C. Randolph (JCR) wrote at Mon, 1 Oct 2001 15:51:39 -0700:
JCR> -(void) setNumber: (NSNumber)value
JCR> {
JCR> if (value && (value != number))
JCR> {
JCR> [value retain];
JCR> [number release];
JCR> number = value;
JCR> }
JCR> }
JCR>
JCR> since a test for zero and a test for equality are probably cheaper than
JCR> looking up an object's external retain count.

That does not look reasonable. Firstly, you prevent zeroing the number by
[obj setNumber:nil] this way -- that might be what you want, but generally it
is not.

It usually is what *I* want. YMMV, and if it does, you can just delete the "value &&" from the test.

Besides, unless it is called really *OFTEN* in some big loop, the gain is
utterly negligible (incidentally, what you meant by "external retain
count"?). Actually, I would recommend the least effective variant for best
code readability (ie. easy debugging and upgrading):

-(void)setNumber:(NSNumber*)value {
[number autorelease];
number=[value retain];
}

I tend to avoid -autorelease when I'm *sure* that I don't care about an object anymore, which is almost always the case in a -set...: method.

-jcr

"I fear all we have done is to awaken a sleeping giant and fill him with a terrible resolve." -Admiral Isoroku Yamamoto, Dec 7, 1941.


  • Prev by Date: Taking a square root of NSDecimalNumber
  • Next by Date: NSWindow hax0r
  • Previous by thread: RE: Applesript and Cocoa
  • Next by thread: Re: [[object autorelease] release]
  • Index(es):
    • Date
    • Thread