On Jun 6, 2008, at 9:16 PM, Ken Thomases wrote:
And... we're back to retain/release.
The issue is, how can one know when this technique is necessary? The supposed rules of GC are, if it's in a stack variable, it's safe. The compiler here is doing something behind the programmer's back, which the programmer can't really predict, that's changing the rules.

Quoting the Garbage Collection Programming Guide: "The initial root set of objects is comprised of global variables, stack variables, and objects with external references. These objects are never considered as garbage"

For some values of "never".

Objective-C 2.0's garbage collection system is incompatible with any optimization which changes which variables are on the stack. More accurately, it's an error if compiler optimizations change what are considered root objects.

The problem here is that there is no way for the compiler to know that the char* bytes is somehow connected to the lifespan of the NSData*. Nor is there any way for the collector to know that the char* bytes is somehow an implied root of the NSData* object.

The compiler isn't changing roots and it isn't doing anything that is a bug -- it is merely optimizing the code to use the resources available by recycling bits of memory that refer to items that, given all knowledge that it has, are no longer needed.

There is actually no guarantee that the -bytes method will return a reference to a malloc'd block of data; it may return an arbitrary pointer into some other Data's hunk of data.

This is an edge case. It is uncommon and the kind of edge case that only exists when you dip below Objective-C and into the realm of C.

b.bum







Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to