I have been having some crashes in my app. When checking the logs and using atos, it is telling me exactly where I get the crash, which is where I tell my NSRunLoop to run:
/**
* Create a new thread for the timer
*
* @version $Revision: 0.1
*/
- (void)createTimerThread {
NSThread *timerThread = [[NSThread alloc] initWithTarget:self selector:@selector(startTimerThread) object:nil];
[timerThread start];
[timerThread release];
}//end
/**
* Start the actual timer
*
* @version $Revision: 0.1
*/
- (void)startTimerThread {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
// Start timer
self.countTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateCounter:) userInfo:nil repeats:YES];
[runLoop run];// <--- Crash happened here
[pool release];
}//end
/**
* Update the counter
*
* @version $Revision: 0.1
*/
- (void)updateCounter:(NSTimer *)theTimer {
// Does tons of timer stuff here
}//end
As you can see, the crash happens on [runLoop run]
but I have no idea why. It normally happens the second time that I call the createTimerThread method.
What am I doing wrong here? All I was wanting to do was run a timer in the background so that it wasn't on the main thread because I needed to update a UILabel
.
Should I be using something new like Grand Central Dispatch (GCD)?