On Mar 16, 2009, at 4:07 PM, Bill Cheeseman wrote:
My question is how to know when to call my -invalidate method to clean up everything related to the ivar once I am through with the ivar.
Either the code creating your object knows when to call -invalidate (through more global knowledge of your application) or it doesn't. If it doesn't, you will need to use -finalize. It seems to me that this is unrelated to how the lifetime for the CFTypeRef is managed.
As noted in my reply to Michael Tsai, I do not call CFMakeCollectable. But I DO declare my CFTypeRef variable as __strong to make sure it is known to the garbage collector.
I don't see any benefit to using __strong if you're not calling CFMakeCollectable. I think that makes the code confusing.
If I have read the Guide correctly, it is not CFMakeCollectable that makes the ivar known to the garbage collector; that's what the __strong declaration is for.
CF *objects* are already known to the garbage collector. __strong tells the collector that the *ivar slot* in your object can hold a reference to a collectable object. If your object ensures that the CFTypeRef always has a retain count greater than zero, there's no point in telling the collector about the slot.
CFMakeCollectable merely makes it immediately eligible for collection by decrementing its retain count to 0. Thus, it seems to me that it is incorrect to say that the ivar lifetime is not managed by GC just because I did not call CFMakeCollectable. In fact, it will be managed by GC, but only after I call my -invalidate method and thereby decrement the ivar's retain count to 0.
Yes, in some sense it's always managed by GC. I was speaking from the point of view of your object. It can either call CFMakeCollectable right away and let the collector handle the CFTypeRef's lifetime, or it can call CFRelease at some later time in -invalidate or -finalize.
--Michael _______________________________________________ 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 arch...@mail-archive.com