Here is my situation. It got complicated, so carry me.
I have a view class, let's call it MyView . It creates a subset of the download indicator, and then launches a background mode that will load data. It also creates a block in which the background queue operation in the main queue will be executed. The block prepares the view by adding another subview, a UITextView , with the loaded data. Of course, for this, the block must have a link to the view.
Thus, the background operation saves the block, and the block saves the view. Still with me?
Sometimes a MyView instance is removed from its supervisor before MyView in the background. And sometimes the operation of the main queue that calls the block is completely cleared before the operation of the background queue is completely cleared. In this case, the MyView instance may receive its -dealloc call in the background thread because the last link to the view belonged to the block, and the last link to the block belonged to the background operation.
UIKit does not like to be called from any thread except the main thread. In the case of a UITextView , it is obvious that it even includes calls to -dealloc . I get EXC_BAD_ACCESS from what is called a "web stream lock" during a -dealloc text view.
I think it is wise to use the last link in the background thread, and I would like to handle this from my implementation of -dealloc , for example:
- (void)dealloc { if ([NSOperationQueue currentQueue] == [NSOperationQueue mainQueue]) {
Therefore, when you call -release on an object, the implementation in NSObject calls -dealloc if the save count reaches zero. Is that all that happens? In other words, is it okay to call -dealloc and not call super ? Am I making some disgusting zombie object or is it fine?
If this is not the case, then what good way to make sure -dealloc is called in the main thread?