Re: Problems with repetetive execution of netstat using NSTask and NSTimer
Re: Problems with repetetive execution of netstat using NSTask and NSTimer
- Subject: Re: Problems with repetetive execution of netstat using NSTask and NSTimer
- From: "Adam R. Maxwell" <email@hidden>
- Date: Tue, 06 Apr 2010 17:25:25 -0700
On Apr 6, 2010, at 12:08 PM, Kazior Fukacz wrote:
> Thanks for your answers!
>
>>> By the way, are you using garbage collection? If not, then you're leaking several objects (those pointed to by 'netstat', 'pipe', and 'string').
>>
>> Yeah, I suspect that the pipes (and corresponding NSFileHandles) are indeed leaking, and that's the real problem. You may also want to create and launch NSTask instances inside an exception handler, since it and NSFileHandle/NSPipe can raise some unexpected exceptions.
>
> I'm coding under Tiger using XCode 2.5. As far as I know garbage collection was introduced in XCode 3 which came with Objective-C 2.0, am I right?
It was introduced with Leopard, so you are definitely leaking objects in the code you posted.
> Anyway, I tried putting a NSAutoreleasePool and draining it every time my method finishes its work.
Randomly adding NSAutoreleasePool instances is /not/ going to help; there's no magic here...
> I also tried releasing the pipe manually. Still no luck.
Read Ken's message again, and combine it with reading the Cocoa memory management docs:
http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/MemoryMgmt/index.html
Until you fix all of the leaks, you'll have problems. I suggesting thinking about who "owns" the NSPipes that you create; once you understand the memory management rules in the docs, this will make sense.
> However, putting "assert(pipe != null)" right before "[netstat setStandardOutput: pipe];" ended up with "(...)/IPShowX/IPShowX.m:32: failed assertion `pipe != nil'". It happened about 15 minutes after launching. This might be helpful in determining what the reason of this problem might be. As we can see it is NSPipe-related. Something about allocation, initialization and releasing?
>
> How is it that it starts to malfunction after such amount of time?
Because the leak builds up over time until you run out of file descriptors, and -[NSPipe init] finally starts returning nil.
_______________________________________________
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