• 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: What's so special about NSString literals? (RE: memory management)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What's so special about NSString literals? (RE: memory management)


  • Subject: Re: What's so special about NSString literals? (RE: memory management)
  • From: Shawn Erickson <email@hidden>
  • Date: Wed, 17 May 2006 20:09:08 -0700


On May 17, 2006, at 7:56 PM, Eric wrote:

Just ot make sure, so by "constant" you're referring to string literals
defined using the @"" notation right?

Yeah @"" are compile time created string instances. Created by the compiler not by you so they are not yours to release.


Are strings defined as NSString *string = [NSString stringWithFormat...]
constants as well? I mean, they are certainly immutable, but I'm not sure
if it's in the same class as string literals.

They are not. Also the concrete class used is an implementation detail of the Cocoa framework not one you should make any assumptions about or depend on in anyway.


If they are the same, doesn't that mean I don't have to worry about releasing manually allocated
NSString like "string" as well?

The Cocoa memory management rules are simple... apply them to your question, no need to second guess :)


Review.. <http://developer.apple.com/documentation/Cocoa/Conceptual/ MemoryMgmt/index.html>

"You take ownership of an object if you create it using a method with "alloc", "copy", or "new" in its name (for example, alloc, copy, or newObject), or if you send it a retain message. You are responsible for releasing objects you own with release or autorelease. Any other time you receive an object, you must not release it."

-Shawn
_______________________________________________
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: 
 >What's so special about NSString literals? (RE: memory management) (From: Eric <email@hidden>)
 >Re: What's so special about NSString literals? (RE: memory management) (From: Nick Zitzmann <email@hidden>)
 >Re: What's so special about NSString literals? (RE: memory management) (From: Eric <email@hidden>)
 >Re: What's so special about NSString literals? (RE: memory management) (From: Eric <email@hidden>)

  • Prev by Date: Re: Can I assume uninitialized variable's value to be nil or 0?
  • Next by Date: Re: Can I assume uninitialized variable's value to be nil or 0?
  • Previous by thread: Re: What's so special about NSString literals? (RE: memory management)
  • Next by thread: Re: What's so special about NSString literals? (RE: memory management)
  • Index(es):
    • Date
    • Thread