Re: Memory Leak while using NSTask repeatedly
Re: Memory Leak while using NSTask repeatedly
- Subject: Re: Memory Leak while using NSTask repeatedly
- From: Cameron Hayne <email@hidden>
- Date: Thu, 16 Oct 2003 14:46:10 -0400
On 16/10/03 12:42 PM, "Huyler, Christopher M" <email@hidden>
wrote:
>
Inside my awakefromnib function I create a new thread
>
and execute a nowait function that runs an infinite loop.
>
[...]
>
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?
Yes. The whole "autorelease" mechanism relies on the NSAutoreleasePool
getting emptied. You need to put
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]
at the beginning of your loop and
[pool release]
at the end.
See:
http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Concept
s/AutoreleasePools.html
--
Cameron Hayne (email@hidden)
Hayne of Tintagel
_______________________________________________
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.