• 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
Memory Leak while using NSTask repeatedly
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 updateTableData: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.

  • Follow-Ups:
    • Re: Memory Leak while using NSTask repeatedly
      • From: Cameron Hayne <email@hidden>
    • Re: Memory Leak while using NSTask repeatedly
      • From: Chris Ridd <email@hidden>
  • Prev by Date: Re: How to track down a double release?
  • Next by Date: Re: No Result Obtained When WebServices Is Called From A Cocoa Client [uses WSMakeStubs]
  • Previous by thread: Re: No Result Obtained When WebServices Is Called From A Cocoa Client [uses WSMakeStubs]
  • Next by thread: Re: Memory Leak while using NSTask repeatedly
  • Index(es):
    • Date
    • Thread