I have an iOS application that's crashing on calls like __destroy_helper_block_253
and __destroy_helper_block_278
and I'm not really sure what either "destroy_helper_block" is referencing or what the number after it is supposed to point to.
Does anyone have any pointers for how to track down where exactly these crashes might be occuring?
Here's an example traceback (note that the lines with __destroy_helper_block
only references the file it's contained in and nothing else, when normally the line number would be included as well).
Thread : Crashed: com.apple.root.default-priority
0 libdispatch.dylib 0x000000018fe0eb2c _dispatch_semaphore_dispose + 60
1 libdispatch.dylib 0x000000018fe0e928 _dispatch_dispose + 56
2 libdispatch.dylib 0x000000018fe0e928 _dispatch_dispose + 56
3 libdispatch.dylib 0x000000018fe0c10c -[OS_dispatch_object _xref_dispose] + 60
4 Example App 0x00000001000fe5a4 __destroy_helper_block_278 (TSExampleApp.m)
5 libsystem_blocks.dylib 0x000000018fe53908 _Block_release + 256
6 Example App 0x00000001000fda18 __destroy_helper_block_253 (TSExampleApp.m)
7 libsystem_blocks.dylib 0x000000018fe53908 _Block_release + 256
8 libdispatch.dylib 0x000000018fe0bfd4 _dispatch_client_callout + 16
9 libdispatch.dylib 0x000000018fe132b8 _dispatch_root_queue_drain + 556
10 libdispatch.dylib 0x000000018fe134fc _dispatch_worker_thread2 + 76
11 libsystem_pthread.dylib 0x000000018ffa16bc _pthread_wqthread + 356
Edit 1: Here's an example of one of the blocks defined in the file where the crash occurs (with application-specific code edited out).
- (void)doSomethingWithCompletion:(void (^)())completion {
void (^ExampleBlock)(NSString *) = ^{
NSNotification *notification = [NSNotification notificationWithName:kExampleNotificationName object:nil userInfo:nil];
[[NSNotificationCenter defaultCenter] postNotification:notification];
if (completion) {
completion();
}
};
// Async network call that calls ExampleBlock on either success or failure below...
}
There are many other blocks in the file, but most of them are provided as arguments to methods instead of being defined first and then referenced later.
Edit 2: Added more context to above function.
copy
it for storage. – Wayworn278
and253
correspond to line numbers containing blocks inTSExampleApp.m
? – DemarcationTSExampleApp.m
? – HairtailNSNotificationCenter
in adispatch_async
on the main queue? – Dembcompletion
block and where is it defined? Looks unusual to call that block from inside your block. Maybe more code/context would help understanding. – NonpartisanExampleBlock
) is called after a network call, in the case of both success or failure.completion()
is called to pass execution back to the original block. I'll add an edit to illustrate. – DonaudoSomethingWithCompletion:
createsExampleBlock
. (2) You start some asynchronous network operation. (3)doSomethingWithCompletion:
returns, andExampleBlock
is released. (4) The asynchronous network operation finishes, and callsExampleBlock
. In this case, the pointer to the block would get dereferenced after it's been deallocated. (Perhaps this is intermittent based on whether the autorelease pool has drained.) In other words: do you guarantee that each block is retained until it's no longer needed? – Kayekayla"Semaphore/group object deallocated while in use"
? – Cariole