Re: memory deallocation
Re: memory deallocation
- Subject: Re: memory deallocation
- From: Michael Ash <email@hidden>
- Date: Sun, 5 Apr 2009 00:28:36 -0400
On Sat, Apr 4, 2009 at 6:02 PM, Andrew Farmer <email@hidden> wrote:
> In your case, if you're trying to create a NSData object with the contents
> of a string, the correct usage is:
>
> char *cstring = "some text";
> return [NSData dataWithBytesNoCopy:cstring length:strlen(cstring)];
>
> We use dataWithBytesNoCopy here because the contents of the string are in
> constant data, and can be guaranteed to not change or go away.
This is no good. NSData will attempt to free your constant string when
it's destroyed. You need to explicitly say freeWhenDone:NO here,
because not specifying it is equivalent to YES.
Mike
_______________________________________________
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