On Dec 31, 2009, at 10:36, Oftenwrong Soong wrote:
> If it is true that the ONLY safe thing you can do in dealloc is release
> instance variables, then where else/how else are you supposed to implement a
> method that is guaranteed to be called upon an object's termination, so that
> you can do final cleanups, such as removing it as an observer or closing
> external resources such as files or network connections? Jerry isn't the only
> one who needs to do such cleanups, nor am I.
It isn't *literally* true, but it's usually true that 'dealloc', in cleaning up
the object's state, puts the object into an inconsistent state, so calling any
method of the object (directly or indirectly) may be problematic. If you're
sure the state isn't inconsistent, or if you're sure the inconsistency isn't
harmful, then you can call other methods.
But ...
For releasing external resources, you should *probably* start using a different
strategy, instead of relying on 'dealloc'. That's because if you ever switch to
garbage collection, there's no 'dealloc' at all, and the equivalent
('finalize') isn't a suitable place to release resources that must be reclaimed
as soon as possible. (Unlike 'dealloc', 'finalize' doesn't happen immediately
after the last reference goes away, and you've no guarantee exactly how long
you'll have to wait for it to be called.)
_______________________________________________
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]