Re: How do I guarantee that an object is dealloced on the main thread?
Re: How do I guarantee that an object is dealloced on the main thread?
- Subject: Re: How do I guarantee that an object is dealloced on the main thread?
- From: Jim Correia <email@hidden>
- Date: Sun, 5 Oct 2008 18:08:21 -0400
On Oct 5, 2008, at 5:41 PM, Brian Stern wrote:
My main reason was just cleanliness. Looking more closely at the
code however, most of which I didn't write, there are some runloop
sources that are removed and calls to NSObject
cancelPreviousPerformRequestsWithTarge:selector:object. Most of the
code that set those things up will have run on the main thread so
should be cleaned up on the main thread. There's some other
networking cleanup that I don't know if it's threadsafe or not.
It's conceivable that I can rework the cleanup so that most of it
happens in the stop method and the dealloc method is mostly empty
That's probably the preferable solution to this problem, even if it is
more work up front.
I guess from your question you don't have a one sentence answer to
my question.
Using classic memory management, your object will be deallocated when
its last owner releases it. If this object has been shared amongst
threads, the it will be deallocated on the last thread which releases
it.
Under garbage collection, you are encouraged not to implement a -
finalize method. If you do implement one, there is no guarantee about
the order it will be called in, if it will be called at all, or what
thread it will be invoked on.
In your -stop method, you know you are done with the object, so doing
your cleanup there (on the main thread, if necessary) seems like an
appropriate solution.
- Jim
_______________________________________________
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