Re: Delayed -dealloc occurs on worker thread if object is "working". How?
Re: Delayed -dealloc occurs on worker thread if object is "working". How?
- Subject: Re: Delayed -dealloc occurs on worker thread if object is "working". How?
- From: Jens Alfke <email@hidden>
- Date: Wed, 2 Jun 2010 11:12:44 -0700
On Jun 2, 2010, at 10:39 AM, Jerry Krinock wrote:
> I allocate an object Foo on the main thread. Then I spin off a secondary thread and give it a long task to do there, but immediately release the object, on the main thread. I expect that the -release invoke -dealloc immediately, on the main thread.
Why? If that were so, the secondary thread would crash when it messaged the now-dealloced object. By telling the object to do something on a secondary thread, you’re implicitly requesting that the object stay alive until that operation finishes. Right?
> To my amazement, the object is not deallocced until the task is finished, and to my further amazement, the dealloc method runs on the secondary thread.
It’s really not a good idea to obsess over the details of when objects get dealloced, unless of course you’re running into dealloced-object crashes or memory leaks.
—Jens_______________________________________________
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