Tôi muốn gửi một đối tượng về chủ đề chính từ chuỗi công nhân. Tuy nhiên, các bể tự động giải phóng có hoạt động giữa các luồng không? Có điều gì sai với mã sau không:Các bể đa luồng và tự động làm việc cùng nhau trong ca cao?
-(void)mainThreadReceiveResult:(id)response
{
[response retain];
/* Do some stuff with response */
[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];
}
Dường như hoạt động tốt. Tuy nhiên, có thể chuỗi công nhân có thể đạt tới [pool release]
trước khi chủ đề chính có thể giữ lại nó không?
ok cảm ơn vì mẹo –