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 (Cocoa-dev@lists.apple.com)

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/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to