• 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: memory deallocation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: memory deallocation
      • From: Andrew Farmer <email@hidden>
References: 
 >memory deallocation (From: Daniel Luis dos Santos <email@hidden>)
 >Re: memory deallocation (From: Andrew Farmer <email@hidden>)

  • Prev by Date: Re: Beachball on Lengthy Task
  • Next by Date: Re: Cocoa user pane equivalent?
  • Previous by thread: Re: memory deallocation
  • Next by thread: Re: memory deallocation
  • Index(es):
    • Date
    • Thread