使用块会导致EXC_BAD_ACCESS [英] Using blocks causes EXC_BAD_ACCESS
本文介绍了使用块会导致EXC_BAD_ACCESS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用块,但这会在几次调用后使我得到EXC_BAD_ACCESS.
I'd like to use blocks, but it causes me a EXC_BAD_ACCESS after a few calls.
我的代码:
- (void) sendBasket {
if (currentSendToBasketBlock != nil) {
// there's already a webservice going... set the new one as waiting
waitingSendToBasketBlock = ^ {
WebServicesModel *webServicesModel = [[[WebServicesModel alloc] init] autorelease];
webServicesModel.delegate = self;
[webServicesModel sendBasketToServer:currentBasket];
[self showBasketBackground];
};
[waitingSendToBasketBlock copy];
} else {
currentSendToBasketBlock = ^ {
WebServicesModel *webServicesModel = [[[WebServicesModel alloc] init] autorelease];
webServicesModel.delegate = self;
[webServicesModel sendBasketToServer:currentBasket];
[self showBasketBackground];
};
[currentSendToBasketBlock copy];
currentSendToBasketBlock();
}
}
Web服务完成后,它将在同一对象上调用特定方法:
When the webservice is finished, it calls a specific method on the same object:
- (void) specificMethod {
if (waitingSendToBasketBlock != nil) {
waitingSendToBasketBlock(); // here, the EXC_BAD_ACCESS happens
waitingSendToBasketBlock = nil;
}
}
我想念什么?乐器找不到僵尸...
What am I missing? Instruments doesn't find a Zombie...
谢谢!
崩溃日志
Thread 0 name: Dispatch queue: com.apple.libdispatch-manager
Thread 0:
0 libsystem_kernel.dylib 0x35590fbc kevent + 24
1 libdispatch.dylib 0x3525bed4 _dispatch_mgr_invoke + 744
2 libdispatch.dylib 0x3525cf3a _dispatch_queue_invoke + 70
3 libdispatch.dylib 0x3525c4ec _dispatch_worker_thread2 + 228
4 libsystem_c.dylib 0x3566758a _pthread_wqthread + 258
5 libsystem_c.dylib 0x35667bbc start_wqthread + 0
Thread 1 name: WebThread
Thread 1:
0 libsystem_kernel.dylib 0x3558dc00 mach_msg_trap + 20
1 libsystem_kernel.dylib 0x3558d758 mach_msg + 44
2 CoreFoundation 0x309582b8 __CFRunLoopServiceMachPort + 88
3 CoreFoundation 0x3095a562 __CFRunLoopRun + 350
4 CoreFoundation 0x308eaebc CFRunLoopRunSpecific + 224
5 CoreFoundation 0x308eadc4 CFRunLoopRunInMode + 52
6 WebCore 0x35f5327e _ZL12RunWebThreadPv + 382
7 libsystem_c.dylib 0x3566630a _pthread_start + 242
8 libsystem_c.dylib 0x35667bb4 thread_start + 0
Thread 2:
0 libsystem_kernel.dylib 0x35591cb0 stat + 12
1 CFNetwork 0x34cccf56 DiskCookieStorage::syncStorageLocked() + 422
2 CFNetwork 0x34c3fa60 PrivateHTTPCookieStorage::syncStorage() + 20
3 CFNetwork 0x34ccaa7e HTTPCookieStorage::syncStorage() + 6
4 CFNetwork 0x34ccaa9c HTTPCookieStorage::_syncTimerFired(__CFRunLoopTimer*, void*) + 12
5 CoreFoundation 0x30957a40 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 8
6 CoreFoundation 0x30959ec4 __CFRunLoopDoTimer + 844
7 CoreFoundation 0x3095a83e __CFRunLoopRun + 1082
8 CoreFoundation 0x308eaebc CFRunLoopRunSpecific + 224
9 CoreFoundation 0x308eadc4 CFRunLoopRunInMode + 52
10 Foundation 0x341dd7f6 +[NSURLConnection(NSURLConnectionReallyInternal) _resourceLoadLoop:] + 206
11 Foundation 0x341d0382 -[NSThread main] + 38
12 Foundation 0x342425c6 __NSThread__main__ + 966
13 libsystem_c.dylib 0x3566630a _pthread_start + 242
14 libsystem_c.dylib 0x35667bb4 thread_start + 0
Thread 3 name: com.apple.CFSocket.private
Thread 3:
0 libsystem_kernel.dylib 0x3558fc60 __select + 20
1 CoreFoundation 0x3095d8f2 __CFSocketManager + 582
2 libsystem_c.dylib 0x3566630a _pthread_start + 242
3 libsystem_c.dylib 0x35667bb4 thread_start + 0
Thread 4:
0 libsystem_kernel.dylib 0x3558dc00 mach_msg_trap + 20
1 libsystem_kernel.dylib 0x3558d758 mach_msg + 44
2 CoreFoundation 0x309582b8 __CFRunLoopServiceMachPort + 88
3 CoreFoundation 0x3095a562 __CFRunLoopRun + 350
4 CoreFoundation 0x308eaebc CFRunLoopRunSpecific + 224
5 CoreFoundation 0x3092d6d2 CFRunLoopRun + 42
6 MyProject 0x0011c41a +[ASIHTTPRequest runRequests] (ASIHTTPRequest.m:4773)
7 Foundation 0x341d0382 -[NSThread main] + 38
8 Foundation 0x342425c6 __NSThread__main__ + 966
9 libsystem_c.dylib 0x3566630a _pthread_start + 242
10 libsystem_c.dylib 0x35667bb4 thread_start + 0
Thread 5:
0 libsystem_kernel.dylib 0x355903ec __workq_kernreturn + 8
1 libsystem_c.dylib 0x356676d8 _pthread_wqthread + 592
2 libsystem_c.dylib 0x35667bbc start_wqthread + 0
Thread 6:
0 libsystem_kernel.dylib 0x355903ec __workq_kernreturn + 8
1 libsystem_c.dylib 0x356676d8 _pthread_wqthread + 592
2 libsystem_c.dylib 0x35667bbc start_wqthread + 0
Thread 7:
0 libsystem_kernel.dylib 0x355903ec __workq_kernreturn + 8
1 libsystem_c.dylib 0x356676d8 _pthread_wqthread + 592
2 libsystem_c.dylib 0x35667bbc start_wqthread + 0
推荐答案
您没有对副本做任何事情,因此您仍在尝试访问存储在堆栈中的块.在呼叫copy
的地方尝试此操作.
You are not doing anything with your copy, therefore you are still attempting to access the block that was stored on the stack. Try this in the place of your call to copy
.
waitingSendToBasketBlock = Block_copy(waitingSendToBasketBlock);
//and
currentSendToBasketBlock = Block_copy(currentSendToBasketBlock);
这篇关于使用块会导致EXC_BAD_ACCESS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文