5

I have an application which runs for days and weeks on a Snow Leopard server. It uses -[NSRunLoop runUntilDate:] to "pause" for ten seconds, perform its task and then pause again. After running for over one hour, my app crashes with the following report:

Crash Report

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000013
Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Application Specific Information:
objc_msgSend() selector name: release

Thread 0 Crashed:  Dispatch queue: com.apple.main-thread
0   libobjc.A.dylib                 0x00007fff84cfef0c objc_msgSend + 40
1   com.apple.CoreFoundation        0x00007fff84e363d1 __CFRunLoopDoSources0 + 1361
2   com.apple.CoreFoundation        0x00007fff84e345c9 __CFRunLoopRun + 873
3   com.apple.CoreFoundation        0x00007fff84e33d8f CFRunLoopRunSpecific + 575
4   com.apple.Foundation            0x00007fff83e73b74 -[NSRunLoop(NSRunLoop)  runMode:beforeDate:] + 270
5   com.apple.Foundation            0x00007fff83ebf19a -[NSRunLoop(NSRunLoop) runUntilDate:] + 78

At first glance I thought my NSRunLoop object is no longer valid and therefore the release message deep within CF causes a crash. However, I don't think that's the case as I obtain the reference to the currentRunLoop object in the line before.

The crash time varies between 1 and 1.5hrs but I can't get a handle on what's causing it. Any comments or opinions or debugging ideas would be greatly appreciated as I'm not sure what to do next.

EDIT: problem solve - please see my answer below

1
  • Can you post some code from the failing method?
    – NJones
    Oct 19, 2011 at 22:25

2 Answers 2

6

Further tests have enabled me to answer my own question:

There is nothing wrong with the run loop. It is the run loop that handles that releases objects in the autorelease pool and that's why problems from any part of the code can show to be related to the Run Loop.

In my case, I had a object that wasn't cleaned up properly. Under normal circumstances this problem would have shown up during memory leak testing. However, this particular issue only arose on the actual client installation when an SMTP server returned an unexpected error message which caused an object to be "left over" and when the run loop eventually tried to clean it up, it came to a grinding halt.

The Short Answer

Crashes in the run loop can be caused by any object in the code. Try to re-create the problem scenario and test for memory leaks to find the offender.

5

I know this doesn't precisely answer your question, but...

I'm not sure if this is an option, since there is no sample code, but have you considered an NSTimer? They're very easy to use to execute code every n seconds.

self.myTimer = [NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(timerTarget:) userInfo:nil repeats:YES];

where myTimer is a NSTimer property of your class.

when your done, and want no more calls.

[self.myTimer invalidate];
self.myTimer = nil;
1
  • Thanks - I am aware of NSTimer and I use it in other applications. It is certainly one of the solutions but I'd prefer to find out what's wrong with the NSRunLoop or maybe something else in my code.
    – helioz
    Oct 19, 2011 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.