Closed joshbernfeld closed 6 years ago
I wonder what the semantics are for calling dispatch_async() on the main queue from the main thread. In any case, this should be safe. Thanks.
Ok time for a second take here. It looks like this code only works properly when dispatch_async is performed synchronously. Based of this backtrace, I think whats happening is once dealloc is set in motion it is impossible to prevent self from releasing. The block attempts to retain self, but that doesn't matter and once the block is executed self is gone.
This was a EXC_BAD_ACCESS crash
I was able to reliably replicate the crash using dispatch_after in order to force async execution. The below code solved the issue. If you would like me to create a new pull request for this please let me know.
- (void)dealloc {
[self stopHandler];
MPVolumeView *volumeView = self.volumeView;
dispatch_async(dispatch_get_main_queue(), ^{
[volumeView removeFromSuperview];
});
}
Oh crap, yes I think you’re right. Please file a new PR.
Fixes the following background thread warning