• 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 is the life of the c string returned by NSString's UTF8String method?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What is the life of the c string returned by NSString's UTF8String method?


  • Subject: Re: What is the life of the c string returned by NSString's UTF8String method?
  • From: Jens Alfke <email@hidden>
  • Date: Fri, 18 Sep 2009 11:51:23 -0700


On Sep 18, 2009, at 11:04 AM, Stuart Malin wrote:

I am under the impression that the reference returned by NSString's UTF8String method is valid for the life of the NSString instance which provided the reference (and further, that the memory of the referenced C string is freed when the NSString is released). Is this correct?

No. The pointer returned is, effectively, autoreleased, and shouldn't be used after the current autorelease pool exits. (I know, it's not an object, but it's actually the -bytes of an autoreleased NSData created by the NSString.)


NSString doesn't generally store its contents in UTF-8, so any time you ask for UTF-8 data it has to allocate space for it.

—Jens_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >What is the life of the c string returned by NSString's UTF8String method? (From: Stuart Malin <email@hidden>)

  • Prev by Date: Re: What is the life of the c string returned by NSString's UTF8String method?
  • Next by Date: Re: Running Safari from application
  • Previous by thread: Re: What is the life of the c string returned by NSString's UTF8String method?
  • Next by thread: Re: What is the life of the c string returned by NSString's UTF8String method?
  • Index(es):
    • Date
    • Thread