Re: dealloc for cleanup versus freeing memory
Re: dealloc for cleanup versus freeing memory
- Subject: Re: dealloc for cleanup versus freeing memory
- From: Chris Suter <email@hidden>
- Date: Tue, 7 Aug 2007 09:06:34 +1000
On 07/08/2007, at 4:07 AM, John Stiles wrote:
I feel as if you remove all the benefits of reference counting if
you add a specific "cleanup" method. If some other method had
retained the object for some reason, what is it supposed to do now?
Explicit cleanup mechanisms only seem to work if you want an object
that can't be copied or shared at all, and you give up all the
benefits of refcounting for what don't appear to be very solid
benefits (basically, things "work better" even if you accidentally
leak an object).
The built-in reference counting should only really be used for
managing the lifetime of the object in memory. If you want a resource
such as a file handle to be reference counted you should reference
count that separately. An object might persist in memory in different
states. A file object, for example, might be open or closed and you
don't want to tie that to whether it exists in memory. You probably
want to ensure that when it's not in memory, the file is closed, but
you might also want the file closed whilst the object remains in memory.
- 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