• 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: Are these the same and correct?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Are these the same and correct?


  • Subject: Re: Are these the same and correct?
  • From: Sherm Pendley <email@hidden>
  • Date: Mon, 14 Nov 2005 15:08:20 -0500

On Nov 14, 2005, at 2:51 PM, Brian O'Brien wrote:

NSNumber *n = [[[NSNumber alloc] initWithShort:val] autorelease];
and
NSNumber *n = [NSNumber numberWithShort:val];

Perhaps I should have specified my assumptions that a) there is an autorelease pool in place and that b) val is an unsigned short.

It doesn't matter.

Internally, numberWithShort: might very well be implemented as "return [[[self alloc] initWithShort:val] autorelease];", in fact in this specific case I'd guess that it probably is.

But as a general rule that's an implementation detail that you don't need to worry about. Other "convenience methods" - [NSApplication sharedApplication] for example - return objects that have not been autoreleased. But it doesn't matter. The point is that you're not responsible for releasing them later; whether that's because they've already been autoreleased, or because they're singletons, or constants, or whatever, is immaterial.

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org

_______________________________________________
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


References: 
 >Are these the same and correct? (From: "Brian O'Brien" <email@hidden>)
 >Re: Are these the same and correct? (From: Sherm Pendley <email@hidden>)
 >Re: Are these the same and correct? (From: Chris Hanson <email@hidden>)
 >Re: Are these the same and correct? (From: Sherm Pendley <email@hidden>)
 >Re: Are these the same and correct? (From: "Brian O'Brien" <email@hidden>)

  • Prev by Date: Re: Are these the same and correct?
  • Next by Date: Re: awakeFromInsert is not called
  • Previous by thread: Re: Are these the same and correct?
  • Next by thread: Re: Are these the same and correct?
  • Index(es):
    • Date
    • Thread