Re: Are these the same and correct?
Re: Are these the same and correct?
- Subject: Re: Are these the same and correct?
- From: "Brian O'Brien" <email@hidden>
- Date: Mon, 14 Nov 2005 12:51:12 -0700
On 14-Nov-05, at 12:42 PM, Sherm Pendley wrote:
On Nov 14, 2005, at 2:20 PM, Chris Hanson wrote:
On Nov 14, 2005, at 11:02 AM, Sherm Pendley wrote:
On Nov 14, 2005, at 1:43 PM, Brian O'Brien wrote:
NSNumber *n = [[[NSNumber alloc] initWithShort:val] autorelease];
and
NSNumber *n = [NSNumber numberWithShort:val];
They're *very* similar; in neither case are you responsible for
releasing n later.
But, as a matter of internal implementation details, there's no
guarantee that n is autoreleased in the second case, although it
quite often will be.
In the second case, you must always treat the object pointed to by
"n" as autoreleased
No, you treat it as something for which you are not responsible. It
might be autoreleased, it might be a constant, a singleton, or
whatever - that's an implementation detail you don't need to worry
about. The sole guarantee is that you don't have to release it.
"Doesn't have to be released" != "Guaranteed to be autoreleased".
sherm--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
Perhaps I should have specified my assumptions that a) there is an
autorelease pool in place and that b) val is an unsigned short.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden