• 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
NSString initWithUTF8String - crazy retainCount with empty string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSString initWithUTF8String - crazy retainCount with empty string


  • Subject: NSString initWithUTF8String - crazy retainCount with empty string
  • From: "Simon Strandgaard" <email@hidden>
  • Date: Sat, 24 Mar 2007 16:33:39 +0100

I have asserts on retainCount a few places in my code,
and today I got surprised that with NSString sets a weird
retainCount when initialized with an empty string.
It looks like a bug to me?

I'm running XCode 2.4.1 on OSX 10.4.8.


So what's the safe way to get a NSString from a cstring?

--
Simon Strandgaard
http://opcoders.com/


---------------------------------------------------------------


#import <Cocoa/Cocoa.h>

int main(int argc, const char** argv)
{
   NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

   {
       const char* s0 = "";
       NSString* s1 = [[NSString alloc] initWithUTF8String: s0];
       int rc = [s1 retainCount];
       NSLog(@"rc = %i", rc);
       // outputs "rc = 2147483647", which I don't understand !!
   }

   {
       const char* s0 = "WHOAMI";
       NSString* s1 = [[NSString alloc] initWithUTF8String: s0];
       int rc = [s1 retainCount];
       NSLog(@"rc = %i", rc);
       // outputs "rc = 1" which is good
   }

   [pool release];
   return 0;
}
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


  • Follow-Ups:
    • Re: NSString initWithUTF8String - crazy retainCount with empty string
      • From: Andy Lee <email@hidden>
    • Re: NSString initWithUTF8String - crazy retainCount with empty string
      • From: "Simon Strandgaard" <email@hidden>
    • Re: NSString initWithUTF8String - crazy retainCount with empty string
      • From: mmalc crawford <email@hidden>
  • Prev by Date: How to access built-in English dictionary?
  • Next by Date: Re: NSString initWithUTF8String - crazy retainCount with empty string
  • Previous by thread: How to access built-in English dictionary?
  • Next by thread: Re: NSString initWithUTF8String - crazy retainCount with empty string
  • Index(es):
    • Date
    • Thread