Skip navigation.
 
mlRe: More GC. Now with NSData
FROM : Alastair Houghton
DATE : Mon Nov 26 19:00:46 2007

On 26 Nov 2007, at 17:56, Sherm Pendley wrote:

> Doesn't -dataWithBytesNoCopy:length:freeWhenDone: do the Right Thing 
> (tm) with respect to marking the returned NSData instance as non-
> collectible when the third param is NO?
>
> IMHO, it should, and if it doesn't, that sounds like a bug.


No, because the NSData instance is still perfectly collectable.  The 
underlying data isn't, but that's not the problem here.  The problem 
is that the underlying NSData (the one that actually holds the memory) 
can be garbage collected if the last reference to it disappears, which 
can easily happen in code like this because the GC ignores interior 
pointers.  i.e. the pointers that the new NSDatas keep to their data 
aren't enough to keep the original NSData alive because they don't 
point to the original NSData object itself.

Kind regards,

Alastair.

--
http://alastairs-place.net

Related mailsAuthorDate
mlMore GC. Now with NSData Paul Sargent Nov 26, 18:20
mlRe: More GC. Now with NSData Alastair Houghton Nov 26, 18:44
mlRe: More GC. Now with NSData Sherm Pendley Nov 26, 18:56
mlRe: More GC. Now with NSData Alastair Houghton Nov 26, 19:00
mlRe: More GC. Now with NSData Paul Sargent Nov 26, 21:38
mlRe: More GC. Now with NSData Alastair Houghton Nov 26, 21:50