I've got a UIViewController
with UICollectionView
, implementing its delegate
and dataSource
. In 95% everything is working ok, but sometimes I get a crash (log, code etc below). I think it happens when successBlock
of myOperation
is executed in same moment as the controller gets deallocated (but I'm not sure).
Considering other question from SOF I assume myCollectionView == nil
, however the delegate
is still pointing somewhere (shouldn't it be changed, it's just assign property as far as I see). I have no idea how to fix such kind of issue, does anyone have any idea?
Crash log:
MyCollectionViewController.m line 0
__destroy_helper_block_
Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x0000000a
Call stack:
libobjc.A.dylib
objc_msgSend + 5
retain
UIKit
-[UICollectionViewController collectionView] + 54
MyAppName
MyCollectionViewController.m line 30
-[MyCollectionViewController dealloc]
MyAppName
MyCollectionViewController.m line 0
__destroy_helper_block_
libsystem_blocks.dylib
_Block_release + 216
MyAppName
MyDownloaderController.m line 0
__destroy_helper_block_75
libsystem_blocks.dylib
_Block_release + 216
MyAppName
MyOperation.m line 0
__destroy_helper_block_19
libsystem_blocks.dylib
_Block_release + 216
MyAppName
MyOperation.m line 0
__destroy_helper_block_112
libsystem_blocks.dylib
_Block_release + 216
UIKit
UIApplicationMain + 1136
MyAppName
main.m line 15
main
Where lines around 30 in MyCollectionViewController:
- (void)dealloc {
if ([self isViewLoaded] && self.collectionView) { // line 30
self.collectionView.delegate = nil;
self.collectionView.dataSource = nil;
self.collectionView = nil;
}
}
My successBlock:
MySuccessHandler successBlock = ^(UIImage *image) {
if (weakCell) {
[weakCell.pageImageView setImage:image];
}
};
User contributions licensed under CC BY-SA 3.0