Created
January 20, 2011 18:31
-
-
Save landonf/788336 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Meanwhile, somewhere in a UI-specific non-thread-safe class | |
- (void) dealloc { | |
// glView is not thread-safe and may only be accessed via the main thread. | |
[_glView release]; | |
[super dealloc]; | |
} | |
- (void) updateUI { | |
// Using GCD to execute a heavy operation on a background thread, and then | |
// report the results on the main thread. | |
// The dispatch calls copy the provided blocks, which increments self's retain count. | |
dispatch_async(queue, ^{ | |
NSData *data = [NSData dataWithContentsOfFile: file]; | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
[self displayData: data]; | |
}); | |
}); | |
// Once the blocks have executed, they will be released. If -release/-autorelease is called on a non-main thread and | |
// the retain count hits 0, our UI classes' non-threadsafe -dealloc will be called on a background thread. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment