Re: Garbage collector vs variable lifetime
Re: Garbage collector vs variable lifetime
- Subject: Re: Garbage collector vs variable lifetime
- From: Chris Hanson <email@hidden>
- Date: Mon, 09 Jun 2008 03:33:06 -0700
On Jun 8, 2008, at 10:03 PM, John Engelhart wrote:
The result from [data self] is invariant, it does not matter if it
is executed immediately after the object is instantiated or just
before [data release], the result is always the same.
There is no way in the Objective-C language as it currently stands
that the compiler can make that assumption.
Since -(id)self causes no side effects, and the result of which is
presumably unused in our hypothetical example, the statement
accomplishes no real work and can be eliminated.
The compiler has no intimate knowledge of what the -self message
actually represents, and *cannot* make that optimization, without
substantial extension to the semantics of Objective-C.
The compiler -- as it currently is -- MUST emit a call to one of the
objc_msgSend* functions for EVERY message expression it sees, without
re-ordering them, due to the semantics of the language.
If Objective-C *is* ever extended to support a construct like
__attribute__((const)) on methods, it must do so in a way that is both
binary- and source-compatible with existing code. Hence you're taking
a purely-hypothetical language construct and extrapolating a problem
that wouldn't be allowed due to
Use of interior pointers in a garbage collected system is hard to get
right, especially when the garbage collection is concurrent/threaded.
That doesn't mean, however, that Objective-C garbage collection in
Leopard is inherently flawed or that it should be avoided: It works
quite well both theoretically and in practice, and it supports the
development of large and well-performing applications.
-- Chris
_______________________________________________
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