Re: Allocation in Pools and threads
Re: Allocation in Pools and threads
- Subject: Re: Allocation in Pools and threads
- From: "Louis C. Sacha" <email@hidden>
- Date: Mon, 14 Jun 2004 22:16:17 -0700
Hello...
If you store an autoreleased object in the instance variable, then
yes it will be zapped when the thread exits. In most cases you would
want to make sure that all objects created within the thread are
properly released before the thread exits, so the issue of when to
release the object you want to return is still important.
A good way to handle this is to use
performSelectorOnMainThread:withObject:waitUnitlDone: to call the
setter for the instance variable with waitUntilDone:TRUE, right
before releasing the thread's autorelease pool and exiting the
thread. If your thread created the object or retained it, then you
could autorelease it before the call back to the main thread, or
release it after the call to the main thread but before the release
of the autorelease pool.
Hope that helps,
Louis
...
The reason I ask is that I have a class that spawns a thread in one
of it's more time consuming methods but I want the method to write
it's results to an instance variable of the class when it's done
doing it's thing. Won't the data the method writes to the instance
variable get zapped when I release the pool?
Have you tried? It shouldn't do it.
Greg
Thanks
Ken
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.