Friday, May 6, 2011

Background method execution using NSThread code example objc

You can execute a method in background mode using detachNewThreadSelector method. For proper memory management, the target method maintains its own AutoreleasePool. [detachNewThreadSelector]


[NSThread detachNewThreadSelector:@selector(doSomethingInBack:) toTarget:self withObject:nil];

-(void) doSomethingInBack:(id)anObject {
NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
// 다른 스레드로 실행할 코드 작성.p
[NSThread exit];
// 메모리 릭 방지.
[autoreleasepool release];
}