我使用XCode4下列代碼上的多線程工作:對象沒有池自動釋放到位
#import <Foundation/Foundation.h>
bool trigger = false;
NSLock *theLock=[NSLock new];
@interface Metronome : NSObject
+(void)tick:(id)param;
@end
@implementation Metronome
+(void)tick:(id)param{
while(1)
{
NSLog(@"TICK\n");
usleep(1000000);
[theLock lock];
trigger = true;
[theLock unlock];
}
}
@end
int main()
{
[NSThread detachNewThreadSelector:@selector(tick:)
toTarget:[Metronome class] withObject:nil];
}
沒有編譯錯誤,但在執行過程中控制檯彈出如下警告:
objc[688]: Object 0x100300ff0 of class NSThread autoreleased with no pool
in place - just leaking - break on objc_autoreleaseNoPool() to debug
我不熟悉obj-C的內存管理。誰可以給我解釋一下這個?非常感謝!