Re: NSTask not cleaning up it's threads
Re: NSTask not cleaning up it's threads
- Subject: Re: NSTask not cleaning up it's threads
- From: Ken Thomases <email@hidden>
- Date: Wed, 15 Oct 2008 00:46:45 -0500
On Oct 14, 2008, at 6:43 AM, C Tearpak wrote:
The following is a test application that demonstrates what I am
seeing. If
you look at the application in Activity monitor, you will see the
threads go
up every second.
Is there something that I am missing? For a long-running application
that
has the following in a thread loop, this causes a huge issue, as I
can't
seem to get these threads to clean up. I have also tried dealloc(),
setting
the pointers to nil and NULL, and calling -terminate: on the NSTask
before I
exit the runCommand:: method;
[...]
int main (int argc, const char * argv[]) {
mainTest* mainT = [mainTest new];
while(true)
{
NSLog([mainT runCommand: @"/bin/date" withArguments:[NSArray new]]);
sleep(1);
}
Have you tried using a run loop and a timer to perform this operation
once a second, rather than a while loop and sleep()?
I suspect that the threads being created by NSTask and/or NSFileHandle
are trying to interact with the main thread using something like -
performSelectorOnMainThread:... with YES for the "wait" parameter.
That requires that the main thread's run loop gets run in the
specified mode (likely the default mode).
You can use Activity Monitor's Sample Process feature to get a sense
of what the extraneous threads are stuck waiting for.
Cheers,
Ken
_______________________________________________
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