I would like to send the object back to the main thread from the workflow. However, do automatic release pools work between threads? Something is wrong with the following code:
-(void)mainThreadReceiveResult:(id)response { [response retain]; [response release]; } -(void)workerThreadDoWork { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; response * response = [[[response alloc] init] autorelease]; response->someData = [self getSomeData]; [delegate performSelectorOnMainThread:@selector(receiveResult:) withObject:response waitUntilDone:NO]; [pool release]; }
Everything seems to be fine. However, is it possible for the worker thread to reach the [pool release] before the main thread can save it?
multithreading objective-c cocoa
Ben reeves
source share