IPhone : NSThread Retain Count

on Thursday, April 9, 2015

Why is the Retain count of my thread = 2?? It gets incremented after the start method why ?

How does Retain count work for NSThreads



@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

NSThread *thread;

@autoreleasepool
{
thread = [[NSThread alloc] initWithTarget:self selector:@selector(check) object:nil];
NSLog(@"RC == %lu",(unsigned long)[thread retainCount]);
[thread start];
}

NSLog(@"RC == %lu",(unsigned long)[thread retainCount]);

}// presently stopped here on breakpoint

-(void)check{
for (int i = 0 ; i< 100000; i++) {
NSLog(@"NEW THREAD ==%d",i);
}
}
@end

0 comments:

Post a Comment