Memory Leak while using NSTask repeatedly
Memory Leak while using NSTask repeatedly
- Subject: Memory Leak while using NSTask repeatedly
- From: "Huyler, Christopher M" <email@hidden>
- Date: Thu, 16 Oct 2003 12:42:26 -0400
- Thread-topic: Memory Leak while using NSTask repeatedly
I'm trying to implement a Preference Pane that monitors the status of
our services. I have used the "Simple Threads" example to manage
multiple threads. Inside my awakefromnib function I create a new thread
and execute a nowait function that runs an infinite loop. The code
isn't finished but here's a snap shot:
- (oneway void)updateTableLoop:(ComCAeTrustAVPrefPane *)controller
// This method runs an infinite loop that checks the status of the
services and reports back
// to the main thread with the updated table information.
{
NSTask *task;
NSPipe *output;
NSFileHandle *handle;
while(1)
{
/* allocate and configure task */
task = [[NSTask alloc] init];
output = [[NSPipe alloc] init];
handle = [output fileHandleForReading];
[task setLaunchPath:@"/bin/ps"];
[task setArguments:[NSArray
arrayWithObjects:@"-c",@"-U",@"root",nil]];
[task setStandardOutput:output];
[task launch];
/* do some stuff */
[task waitUntilExit];
/* clean-up before running again */
[output release];
[handle release];
[linesArray release];
[task release];
/*[controller updateTable
Data:servicesArray];*/
sleep(1);
}
}
So basically it calls "ps" over and over again to see whether our
services are active. If I comment out the "task launch" and "task
waitUntilExit" and run it, I don't get any memory leaks. However, if I
uncomment those lines, I start loosing 2-4 Kb a second (each time the
loop runs).
Is there some more clean-up that I am missing?
--
Christopher Huyler
Computer Associates
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.