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: Ken Thomases <email@hidden>
- Date: Mon, 5 Apr 2010 17:02:31 -0500
On Apr 5, 2010, at 4:05 PM, Kazior Fukacz wrote:
> When I run it, it keeps working perfectly fine for a few minutes, then stops refreshing the IP and prints:
>
> IPShowX[14917] *** NSTimer discarding exception '*** -[NSCFDictionary setObject:forKey:]: attempt to insert nil value' that raised during firing of timer with target 34e410 and selector 'getGameIP:'
>
> every 3 seconds (what's my NSTimer's interval). It's my first Cocoa application and I don't really understand the problem.
Well, I'm not sure how much you do understand.
Cocoa container classes can't contain 'nil' values; they can only contain actual objects.
Something, somewhere is attempting to insert a nil value into a NSMutableDictionary-derived object. This causes an exception to be raised.
As a convenience, NSTimer catches and discards any exceptions which happen during execution of its selector, and logs the above message when it happens. It also, apparently, stops the timer from repeating subsequently.
It will help in diagnosing this to run your program under the debugger. From Xcode's Run menu, enable Stop on Objective-C Exceptions. Then, when the exception occurs the debugger will suspend the program and allow you to investigate. You can see from the stack trace where exactly in your method the problem is happening. You can also check out some other program state (e.g. variable values) to see if that explains what's happening.
I suspect you may be getting output from netstat that is not in pure ASCII. Then, 'string' will be nil and that will cascade through so that IPSubstr is nil and IPSplit is nil. Then, you're passing a nil value to [IPField setStringValue:].
By the way, are you using garbage collection? If not, then you're leaking several objects (those pointed to by 'netstat', 'pipe', and 'string').
Regards,
Ken
_______________________________________________
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