Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Running an NSTask Within an NSThread



Hi Jon,


I'm writing an app that needs to run a fairly lengthy background
process, but the process itself is an NSTask.  Does the task itself
run on its own thread anyway or am I better spawning a new thread from
my main one?  What would be any possible disadvantage? The docs say
that a task runs in a separate memory space to the calling app, but I
don't know if that's the same thing.

Task that you intend to run is actually a separate process and NSTask class provides
the necessary setup to run that process and get the results. It hooks to the run loop of the
thread in which it was executed.



When I don't span a new thread I get NSLogs showing that two calls to my -taskDidFinish:(NSNotification *)note method and a crash.
I do not have an idea why it fires -taskDidFinish notification twice. And the reason why
it crashes is evident from your code that you end up releasing the task object twice as
the notification is called twice. To be on safer side, soon after releasing the object, initialize
it to nil.



When I spawn a thread, I get no calls to the -taskDidFinsh method, therefore I have a memory leak! Any ideas?

I suspect that you do not have a run loop running in your secondary thread. Thats the exact reason
why you are not getting the notification and thus your object is not being released.




Regards
Shripada

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.