Created
July 30, 2014 12:23
-
-
Save stigi/11cccd6778ebd83aae49 to your computer and use it in GitHub Desktop.
Bad idea
This file contains 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
MyCrazyBlock block = ^(BOOL *stop) { | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ | |
// do some work | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
*stop = YES; | |
}); | |
}); | |
}; | |
// in your object | |
if (block) block(&self.shouldStop); |
just a wild guess, but what if you call the block with a weak pointer to self?
__weak typeof(self) weakSelf = self;
if (block) block(&weakSelf.shouldStop);
Please ignore the fact that setting the stop
BOOL asynchronously never worked anyway ;)
@hiDominik: should not make any difference, as ARC only manages object retain counts. we're dealing with a pointer into an objects memory space here. Nothing that could be retained.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When your object is released and deallocated (might happen during "some work") the pointer to the stop BOOL is still held but points to invalid (maybe even some other objects) memory. When you write to its location you might end up writing to some other objects memory.
Result: Funky crashes (
EXC_BAD_ACCESS
&SIGSEGV
) all over the place.