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: Chris Suter <email@hidden>
- Date: Thu, 7 Feb 2008 12:48:22 +1100
On 07/02/2008, at 12:06 PM, John Engelhart wrote:
However, consider for a moment if it was a type attribute, and
followed type attribute rules, and how this would effect the
examples cited. Off the top of my head, I think treating it as a
type attribute would have prevent every single error I've pointed
out. Hypothetically, consider if UTF8String propagated the __strong
type, and the assignment of its pointer to the ivar 'const char *'.
The compiler would fail to compile the code, and generate an error.
I don't think it should be a type qualifier. It would mean that you
wouldn't be able to do things like:
puts ([myString UTF8String])
without getting a compiler warning.
Oddly, I had to add a second NSLog() in order to get some kind of
lossage, but I think it's fair to chalk this up to the semi-random
nature of allocations.
I think that would have been because the pointer returned by
UTF8String was still on the stack or in a register.
The above example is now perfectly legal by everyones definition of
how things were under retain/release, and I correctly clear the
pointer before it goes out of scope, and demonstrates that the GC
system can, and does, reclaim live data out from under you.
I think your example is contrived. Whilst it's legal in the retain/
release world you wouldn't ever write anything like that.
The solution to all of this is, as has already been stated, is to
understand the contract that UTF8String promises and to make your own
arrangements if you want to hang on to the value.
- Chris
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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