Re: [[object autorelease] release]
Re: [[object autorelease] release]
- Subject: Re: [[object autorelease] release]
- From: "John C. Randolph" <email@hidden>
- Date: Mon, 1 Oct 2001 15:51:39 -0700
On Monday, October 1, 2001, at 03:35 PM, Andrew Pinski wrote:
One thing I would do is
-(void) setNumber: (NSNumber)value
{
[value retain];
[number release];
number = value;
}
Just in case number = value and the reference count is only one, which
can happen(i.e. [self setNumber: number]).
I tend to also test whether value is nil, and if it differs from the
ivar I've already got, e.g:
-(void) setNumber: (NSNumber)value
{
if (value && (value != number))
{
[value retain];
[number release];
number = value;
}
}
since a test for zero and a test for equality are probably cheaper than
looking up an object's external retain count.
-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.