Re: NSTask in separate thread is leaking memory
Re: NSTask in separate thread is leaking memory
- Subject: Re: NSTask in separate thread is leaking memory
- From: Ken Thomases <email@hidden>
- Date: Wed, 4 Feb 2009 08:51:58 -0600
On Feb 4, 2009, at 7:25 AM, Oleg Krupnov wrote:
Marvelous! Thank you very much, Ken. All of your advices worked like
a charm.
You're welcome. I'm glad I could help.
So the problem is solved for now, but one question still left open for
the future is the following: would it be thread-safe to use NSTask in
the way I originally attempted?
Yes. It's safe to use an NSTask in a secondary thread, just so long
as a given instance of NSTask isn't being accessed by two different
threads.
If yes, why did it leak? The leak was
reported somewhere inside NSTask internal initialization code. Funny
enough, the leak disappeared if I made one superfluous -release call
on NSTask.
As I said, I believe (but don't know for sure) that the leak was due
to the fact that you didn't run the run loop of the secondary thread.
I think that NSTask installs a run loop source to monitor the other
process. There's probably some housekeeping that has to happen when
the other process terminates, which will only be noticed if the run
loop of the thread is running when that happens.
You can file a bug against either the behavior (if you think that
NSTask should take care of its housekeeping in some other way) or
against the documentation (if you think the requirement to run the run
loop should be explicit).
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