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: "Michael Ash" <email@hidden>
- Date: Sun, 5 Oct 2008 22:27:59 -0400
On Sun, Oct 5, 2008 at 4:43 PM, Brian Stern <email@hidden> wrote:
> How do I guarantee that object X is dealloced on the main thread?
I'd suggest that, if at all possible, your dealloc method shouldn't
care what thread it runs in. Fortunately most resource cleanup can run
anywhere. If your dealloc method includes actions which can only be
run on the main thread, it *may* be an indication that you're doing
something you shouldn't.
If you really must run cleanup tasks on the main thread, then you can
run them with performSelectorOnMainThread from your dealloc method.
Beware not to use "self" for any of the arguments, though. That method
is likely to retain its arguments, which could cause unpleasantness if
you pass it an object that's in the middle of being destroyed.
As for synchronizing with a thread's termination, this is an area in
which the NSThread API has chronically fallen short. It's trivial if
you use pthreads (using pthread_join), so one way around the problem
would be to switch to pthreads instead of using NSThread.
Mike
_______________________________________________
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