Re: Passing data between NSOperation and main thread
Re: Passing data between NSOperation and main thread
- Subject: Re: Passing data between NSOperation and main thread
- From: Greg Guerin <email@hidden>
- Date: Sun, 26 Jul 2009 18:02:46 -0700
Meik Schuetz wrote:
I am just starting to test my little application for leaks using
Instruments. I have got a NSOperation which is doing some JSON
communication stuff with my server. The NSOperation is sending an
NSDictionary object back to the main thread (using a delegate and
performSelectorOnMainThread) when the thread is about to complete.
How was the NSDictionary produced? Is it in the sending thread's
autorelease pool?
Does the sending thread own the NSDictionary? Are you transferring
ownership to the receiving thread? What does the receiving thread do
with the NSDictionary once it's received? Does it relinquish
ownership properly?
It happens that the Leaks instrument is finding leaks just right
there. To analyse the problem, I created a test app having the same
communication method in the main thread.
Curiously, the Leaks instrument is not finding any leak in this
test application.
Why should that be curious? If it's all running on the main thread,
then there won't be any inter-thread ownership issues, nor will there
be any inter-thread autorelease pool issues. You can't accurately
simulate asynchronous threads using a single-threaded test.
I believe that the NSOperation's main method is encapsulated in
some autorelease pool. Is there anything that I need to worry about
when passing an NSDictionary between threads?
Ownership. It all comes down to object ownership. If you understand
ownership, and transfer of ownership, then things will work
properly. If not, then things will go wrong.
You will probably have to post your code. There's no way to know
exactly what it's doing just by reading your description.
-- GG
_______________________________________________
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