Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful
Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful
- Subject: Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful
- From: Alastair Houghton <email@hidden>
- Date: Wed, 6 Feb 2008 19:12:07 +0000
On 6 Feb 2008, at 17:52, Hamish Allan wrote:
On Feb 6, 2008 2:59 PM, John Engelhart <email@hidden>
wrote:
"I'll take 'Not relevant' for $200 and 'Misunderstands the
fundamentals' for the win, Alex."
Speaking of "not relevant" and "misunderstands the fundamentals":
1) UTF8String returns a non-__strong pointer.
__strong isn't a type qualifier, it's an attribute (in the sense of
the __attribute__ keyword). The distinction is perhaps a bit subtle,
especially as attributes can be attached to a typedef'd type, but it's
the reason that you can put __strong anywhere in a variable
declaration and it still has the same effect. It *isn't* like const
or volatile, and the ANSI C rules regarding type qualifiers absolutely
*do not* apply.
Furthermore I *think* (and this is from memory, based on some work I
did on GCC several years ago, so I might be wrong) that if you write
something like
void * __strong MyFunction(void);
you'll find that the __strong attribute is attached to the *function*
rather than to the type. In any case it's going to be ignored because
__strong only really affects variables, not types or functions.
2) You fail to copy the data at that pointer.
3) You cry foul when that data disappears.
Well the bug is *either* ignoring the bit in the -UTF8String docs
where it says you should copy the string (though that does read like
it was only intended to talk about the non-GC case---I just filed <rdar://5727581
> asking for a clarification), or not using __strong on the variable
you're storing the result in.
A garbage collection systems sine qua non is to free the programmer
from having to deal with the issues memory allocation.
Exactly. So stop getting your knickers in a twist about whether or not
UTF8String actually returns memory from NSAllocateCollectable(), and
simply copy the result as required by the documentation for
UTF8String.
Indeed, I rather wish I hadn't mentioned NSAllocateCollectable(),
since I think it's only muddied the waters further.
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