• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: Question on threads running in my Foundation tool
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Question on threads running in my Foundation tool


  • Subject: RE: Question on threads running in my Foundation tool
  • From: Josh Freeman <email@hidden>
  • Date: Mon, 23 Feb 2009 00:54:15 -0500

Hi,


On Feb 22, 2009, at 9:35 AM, Charles E. Heizer wrote:

The issue I'm seeing is that for every time I call NSThread so not to block the run loop it runs it's course but when it completes it leaves a hanging thread. So every 60 seconds I see an additional thread get added and never drops it once completed.

...

-(void)runSoftwareUpdate
{
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath: @"/usr/sbin/softwareupdate"];

NSArray *arguments;
arguments = [NSArray arrayWithObjects: @"-l", nil];
[task setArguments: arguments];

NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];

NSFileHandle *file;
file = [pipe fileHandleForReading];

[task launch];

NSData *data;
data = [file readDataToEndOfFile];

NSString *string;
string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog (@"Got a result \n%@", string);
}


Could the hanging thread be due to the alloc'd NSTask not being released?


<shameless self-plug>

You might be interested in checking out the source code to an open-source app I wrote, DAA Converter; It's a Cocoa wrapper for a 3rd-party command-line tool.

The sources contain (hopefully helpful) examples for both ways of using NSTask - asynchronously & synchronously (the latter for when the task will exit very quickly). There's no explicit use of NSThread, NSRunLoop, or NSAutoreleasePool, since the NSTasks are created by the main thread.

   DAA Converter's sources are the bottom of the app's page:
http://www.twilightedge.com/mac/daaconverter

The NSTask code is found in DAAC_ConversionTask.m (async begins in the 'beginDAA2ISOTaskWithDAAFile:ISOFile:' method, sync begins & ends in the 'daa2isoCredits' method).

Cheers,

Josh

_______________________________________________

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


  • Follow-Ups:
    • Re: Question on threads running in my Foundation tool
      • From: "Charles E. Heizer" <email@hidden>
  • Prev by Date: (Almost)Newbie Question: Implementing / use a free available source code editor
  • Next by Date: reloading IKImageBrowserView in an IBAction
  • Previous by thread: Re: Question on threads running in my Foundation tool
  • Next by thread: Re: Question on threads running in my Foundation tool
  • Index(es):
    • Date
    • Thread