내 앱에서 충돌이 발생했습니다. 로그를 확인하고 ATOS를 사용할 때, 내가 실행하는 내 NSRunLoop에게 어디 인 충돌을 얻을 정확히 말해되지 않습니다 :iOS : NSThread에서 타이머를 실행하면 EXC_BAD_ACCESS가 발생합니까?
/**
* 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
당신이 볼 수 있듯이, 충돌이 [runLoop run]
에서 발생하지만 난 더이 왜 그런지. 일반적으로 두 번째로 createTimerThread 메소드를 호출합니다.
내가 뭘 잘못하고 있니? 내가 원하는 것은 배경에서 타이머를 실행하여 UILabel
을 업데이트해야하기 때문에 주 스레드에 없었기 때문입니다.
Grand Central Dispatch (GCD)와 같은 새로운 것을 사용해야합니까?
NSZombies를 활성화하면 이유를 찾을 수 있습니다. EXC_BAD_ACCESS는 출시되는 무언가와 관련이 있습니다. 이는 a.k.a 좀비가 느슨해져서는 안됩니다. –
백그라운드 스레드에서 UILabel에 액세스하고 있습니까? 아니면 다른 UI 요소입니까? – JustSid
updateCounter 메서드에서 UILable을 업데이트합니다. 그래서, 그것이 현재 백그라운드에 있는지 확실하지 않습니다. –