我剛開始使用的OBJ-C /可可使用線程和我遇到一些麻煩。我得到這個錯誤在控制檯:可可線程錯誤
2010-02-15 09:18:41.467 Timer[1007:4503] *** __NSAutoreleaseNoPool(): Object 0x10012adc0 of class __NSCFDate autoreleased with no pool in place - just leaking 2010-02-15 09:18:41.478 Timer[1007:4503] *** __NSAutoreleaseNoPool(): Object 0x1003362b0 of class NSCFTimer autoreleased with no pool in place - just leaking
這裏是代碼創建新的線程:
// Timer
JHTimer *timer = [[JHTimer alloc] init];
[timer setMinTextLabel:minTextLabel];
[timer setSecTextLabel:secTextLabel];
[timer setHrTextLabel:hrTextLabel];
timerTimeInt = 30;
[timer setTimerInterval:timerTimeInt];
[NSThread detachNewThreadSelector:@selector(start) toTarget:timer withObject:nil];
和創建自動釋放池的代碼(創建計時器啓動方法):
- (void)main {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
}
- (void)start {
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerDidUpdate:) userInfo:nil repeats:YES];
NSLog(@"Test");
}
,我可以」不知道這是錯的
您是否正在發佈您的計時器參考? – Zinc
也許你可以把'[self main];'作爲你的'start'方法的第一行。 – dreamlax