On Tue, Aug 12, 2008 at 11:30 PM, Quincey Morris <[EMAIL PROTECTED]> wrote: > On Aug 12, 2008, at 22:52, Ken Ferry wrote: > >> In general, you don't need to CFRetain an object to keep it alive >> while it's on the stack. The fact that it's on the stack is enough. >> If this wasn't true, there'd be a race, since the collector might >> destroy the object before you retained it. > > Unless I misunderstand your point, its being on the stack will only keep it > alive if CFMakeCollectable has already been called on it. In a case where > you're given a CF-type object that you don't own, I don't think you can > assume that. If it has not been made collectable, it's being kept alive by a > non-zero retain count, or by having being autoreleased, either of which will > keep it alive long enough for you to retain it.
I think Malcolm prefers we point at the docs rather than try to explain in our own words. :-) http://developer.apple.com/documentation/Cocoa/Conceptual/GarbageCollection/Articles/gcCoreFoundation.html "By default, all Core Foundation objects are allocated in the garbage collection zone." "The difference between the garbage-collected environment and managed memory environment is in the timing of the object's deallocation. In a managed memory environment, when the object's retain count drops to 0 it is deallocated immediately; in a garbage-collected environment, what happens when a Core Foundation object's retain count transitions from 1 to 0 depends on where it resides in memory: If the object is in the malloc zone, it is deallocated immediately. If the object is in the garbage collected zone, the last CFRelease() does not immediately free the object, it simply makes it eligible to be reclaimed by the collector when it is discovered to be unreachableāthat is, once all strong references to it are gone. Thus as long as the object is still referenced from an object-type instance variable (that hasn't been marked as__weak), a register, the stack, or a global variable, it will not be collected." "CFMakeCollectable calls CFRelease, but has two supplementary features: first, it ensures that the object was allocated in the scanned zone; second, it's a no-op if you use managed memory. (In addition, it more clearly signals your intent.) " -Ken Cocoa Frameworks _______________________________________________ Cocoa-dev mailing list ([email protected]) 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]
