Re: NSTask setStandardOutput bug?
Re: NSTask setStandardOutput bug?
- Subject: Re: NSTask setStandardOutput bug?
- From: John Stiles <email@hidden>
- Date: Thu, 20 Dec 2007 18:49:31 -0800
Wrap the body of this loop with an autorelease pool and see if this
makes the problem go away.
You're not autoreleasing anything, but Cocoa may internally have
performed the equivalent of [[someObject retain] autorelease].
Also, you are leaking "string".
justin webster wrote:
I have a problem with running this code more than 248 times.
It is a simplified version of my implementation which is based on an
example from cocoaDevCentral
http://cocoadevcentral.com/articles/000031.php
this is a loop for the sake of demonstrating the problem:
int l;
for(l=0; l< 250; l++){
NSLog(@"%d", l);
NSTask *ps=[[NSTask alloc] init];
NSPipe *pipe=[[NSPipe alloc] init];
NSFileHandle *handle;
[ps setLaunchPath:@"/bin/ps"];
[ps setArguments:[NSArray arrayWithObjects:@"-p", PID, @"-o" ,
@"pcpu", nil]];
[ps setStandardOutput:pipe];
handle=[pipe fileHandleForReading];
[ps launch];
NSString *string = [[NSString alloc] initWithData:[handle
readDataToEndOfFile] encoding:NSASCIIStringEncoding];
NSLog(string);
[ps release];
[pipe release];
}
where 'PID' is any valid process ID.
it invariably fails after the 248th iteration with the error:
[NSCFDictionary setObject:forKey:]: attempt to insert nil value
I narrowed the crash down to the setStandardOutput call.
I can only guess it is some kind of memory management issue but can't
see how.
if I comment out the '[ps launch]' line (and the two after it) it does
exactly 124 iterations before crashing.
any ideas?
_______________________________________________
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
_______________________________________________
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