• 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: NSData dataWithBytes:NoCopy:length free()'s the data (bug)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSData dataWithBytes:NoCopy:length free()'s the data (bug)


  • Subject: Re: NSData dataWithBytes:NoCopy:length free()'s the data (bug)
  • From: Allan Odgaard <email@hidden>
  • Date: Fri, 1 Feb 2002 04:25:06 +0100

On fredag, februar 1, 2002, at 03:44 , Ondra Cada wrote:

You want the newly created data to use directly the
buffer "bytes", which was, though, never allocated. Therefore, naturally,
when it is freed (as the data object gets deallocated) the memory manager
complains.

I don't really see why NSData should call free() on my data. These data can be allocated in a dozen other ways than using the same malloc() operator which NSData's free() should be paired with, or they could just be a subset of a malloc allocation..

If Apple really did decide that this would be a good idea, then I wish they'd state it in their documentation. Cause it sure goes against my intuition...

Use just dataWithBytes:length:. Or retain the data, never releasing it. Or
malloc the buffer.

When I want to use the NoCopy then it's to cut down on the memory usage and also improve the time complexity (copy is linear) -- which is the reason I see for implementing such a feature, not to hand over the responsibility of calling free(), the latter just make the code less transparent, because malloc() and free() doesn't get paired semantically...


  • Prev by Date: Sliding tab-pages in ProjectBuilder: custom subclass?
  • Next by Date: Re: NSData dataWithBytes:NoCopy:length free()'s the data (bug)
  • Previous by thread: NSData dataWithBytes:NoCopy:length free()'s the data (bug)
  • Next by thread: Re: NSData dataWithBytes:NoCopy:length free()'s the data (bug)
  • Index(es):
    • Date
    • Thread