• 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: -[NSString stringWithCString:encoding:] memory management question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -[NSString stringWithCString:encoding:] memory management question


  • Subject: Re: -[NSString stringWithCString:encoding:] memory management question
  • From: "Hank Heijink (Mailinglists)" <email@hidden>
  • Date: Thu, 12 Nov 2009 09:10:11 -0500

-initWithCString:encoding: should copy the bytes. You can verify that yourself with a small test:

char buf[10+1] = "0123456789";
NSString *s = [[NSString alloc] initWithCString:buf encoding:NSASCIIStringEncoding];
NSLog(@"before %@", s);
memset(buf, 'x', 10);
NSLog(@"after %@", s);


If the bytes were not copied then `before` and `after` would differ.

I don't see any memory errors in your code. My next suspect would be memory errors in getMetadata() or getLengthOfMetadata(). Try replacing getLengthOfMetadata(...) with pcLength=10, and/or getMetadata(...) with memset(pBuffer, 'x', pcLength). If one of those changes makes the crash go away then those two functions look much more suspicious.

Sure enough, replacing those functions makes the crash go away. Unfortunately, those functions are in a third-party library, and I can't get around using them. I'll contact the developers of that library and see what we can work out.


Thanks!

Hank

_______________________________________________

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: 
 >-[NSString stringWithCString:encoding:] memory management question (From: "Hank Heijink (Mailinglists)" <email@hidden>)
 >Re: -[NSString stringWithCString:encoding:] memory management question (From: Greg Parker <email@hidden>)

  • Prev by Date: Re: [MEET] CocoaHeads-NYC this Thursday, 11/12 (tonight)
  • Next by Date: Re: -[NSString stringWithCString:encoding:] memory management question
  • Previous by thread: Re: -[NSString stringWithCString:encoding:] memory management question
  • Next by thread: Re: -[NSString stringWithCString:encoding:] memory management question
  • Index(es):
    • Date
    • Thread