Re: More GC. Now with NSData
Re: More GC. Now with NSData
- Subject: Re: More GC. Now with NSData
- From: Alastair Houghton <email@hidden>
- Date: Mon, 26 Nov 2007 18:00:46 +0000
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
_______________________________________________
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