I ran into the problem of using a third-party library, and I'm not sure what a common template is to solve it.
I am using the asi-http-request class, which asynchronously retrieves HTTP objects using a stream.
In my objects, the dealloc () method, I do
[request setDelegate:nil]
[request release]
However, the delegate sometimes calls the call after this has happened. (I see when this happens, the delegate field of the request object is nil.) This sometimes fails if the delegate has already been destroyed.
I think this is a race condition. The code from ASIHTTPRequest that calls the delegate looks like this:
if ([self didFinishSelector] && [[self delegate] respondsToSelector:[self didFinishSelector]]) {
[[self delegate] performSelectorOnMainThread:[self didFinishSelector] withObject:self waitUntilDone:[NSThread isMainThread]];
}
The problem occurs if the calling (but not completed) executor of SelectorOnMainThread is called when the setDelegate call occurs on the main thread.
'didFinishSelector', ( ), - , , .
:
http://groups.google.com/group/asihttprequest/browse_thread/thread/721220b9645f4a42
"" !