1

Imagine I create and execute an NSThread object using detachNewThreadSelector:toTarget:withObject:. The method executed by the thread might look like this:

- (void)search {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    // perform a lengthy search here.

    [pool release];
}

I then might use the cancel method to kill the thread while it's running, before the pool gets released. What happens to the NSAutoreleasePool object? I suppose it will leak, won't it?

misfit153
  • 11
  • 1

2 Answers2

2

-(void)cancel doesn't force cancellation, it merely requests it. Your -(void)search will run to completion. Read "Responding to the Cancel Command" for details.

outis
  • 75,655
  • 22
  • 151
  • 221
1

I highly recommend NSOperationQueue for simple concurrent tasks.

ohho
  • 50,879
  • 75
  • 256
  • 383