私はARCを使用していますし、iOS6に、私は奇妙なクラッシュを取得sometiesを呼び出す:スタックトレースメソッドの前ではE08gdbがリモートエラーを返しました:E08たときに完了ブロック(EXC_BAD_ACCESS)
: GDBはリモートエラーを返しました完了ブロックを呼び出す行にあります。私はブロックとARCについて多くを読んで、しかしfolling文脈でそれらを使用したとき、私はまだ自信がないよ:
(簡略化された方法を、いくつかのコード取り残さ)コードを呼び出す
- (void) method1: (void(^)(NSMutableArray *a)) completionBlock withFailedBlock:(void(^)(NSInteger errorCode,NSString *error)) failedBlock {
__weak Controller *weakSelf = self;
...
if(condition)
completionBlock(weakSelf.a);
//still do method2, since we might get updated data
[weakself.service method2:^(NSMutableArray *a2) {
weakSelf.shouldRefresh = NO;
...
completionBlock(a2); //<-- sometimes crashes here
} withFailedBlock:^(NSInteger errorCode, NSString *error) {
failedBlock(errorCode, error);
}];
} withFailedBlock:^(NSInteger errorCode, NSString *error) {
failedBlock(errorCode, error);
}];
を:
[[Controller sharedController] method1:^(NSMutableArray *a) {
//save result in model (singleton)
[Model sharedModel].a = a;
[weakSelf refreshUI];
} withFailedBlock:^(NSInteger errorCode,NSString *error) {
;//show alert
}];
ブロックとその周囲の値を調べると、大丈夫です。私もNSZombieを持っています。 ブロック内から参照されているので、私のcompletionBlockは自動的にコピーされます。
私はここで何が欠けていますか? iOS5と4.3でもクラッシュしましたが、gdbのリモートからはエラーが返されませんでした:E08。デバッガからの情報もそのような場合には役に立たなかった。私はPLWeakCompatibilityを使用していますので、iOS4.3で__weakをサポートできます。
クラッシュはおそらくブロックが実行するコードにあります。なぜコードを投稿しないのですか? – Ecarrion
投稿を編集してこの情報を追加しました – splinter
オブジェクトをコピーするときにC++プロジェクトでこのエラーが発生しました。 – Ross