Re: NSDocument, NSManagedObjectContext do Stuff in -dealloc, Cause Crash
Re: NSDocument, NSManagedObjectContext do Stuff in -dealloc, Cause Crash
- Subject: Re: NSDocument, NSManagedObjectContext do Stuff in -dealloc, Cause Crash
- From: Quincey Morris <email@hidden>
- Date: Thu, 31 Dec 2009 12:14:20 -0800
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@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