Re: mutableBytes Creates Autoreleased Objects
Re: mutableBytes Creates Autoreleased Objects
- Subject: Re: mutableBytes Creates Autoreleased Objects
- From: Ken Thomases <email@hidden>
- Date: Sat, 12 May 2012 12:17:57 -0500
On May 12, 2012, at 11:37 AM, Quincey Morris wrote:
> No, the pointer returned by 'mutableBytes' is an interior pointer. It *isn't* an object pointer. (Well, as an implementation detail, it may happen to point to an object's memory, but it often doesn't.)
>
> As soon as the NSMutableData's lifetime ends -- when it reaches its dealloc -- the 'mutableBytes' pointer becomes instantly invalid.
That's not necessarily so. And/or requesting the mutableBytes may do the equivalent of retain+autorelease on the NSMutableData.
Consider an inexact analog. The -[NSString UTF8String] method seems to create an autoreleased NSData (or similar object) to hold the UTF-8-encoded C string that it returns. It's not returning the NSData object, obviously, it's just using the autoreleased lifetime to manage the lifetime of the C string.
Anyway, NSMutableData *could* be doing something similar. I don't know if it is or isn't. I believe that Andreas is saying that his testing shows that it is. If it is, Apple may have done this specifically to avoid a problem with internal pointers in ARC.
Regards,
Ken
_______________________________________________
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