8

내가 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도 사용하고 있습니다. 내 완료 블록은 블록 내에서 참조되므로 자동으로 복사됩니다.

무엇이 여기에 있습니까? iOS5 및 4.3에서도 충돌이 발생했지만 gdb 리모컨은 오류를 반환하지 않았습니다. E08. 디버거의 정보도 이러한 경우 유용하지 않았습니다. PLWeakCompatibility을 사용하여 iOS4.3에서 __weak을 지원할 수 있습니다.

+0

충돌이 코드 블록에서 실행되는 이유는 무엇입니까? 코드를 게시하면 어떨까요? – Ecarrion

+0

이 정보를 포함하도록 게시물을 편집했습니다. – splinter

+0

오브젝트를 복사 할 때 C++ 프로젝트에서이 오류가 발생했습니다. – Ross

답변

0

이 문제가 계속 발생합니까?

왜이 경우 weakSelf가 필요한가요? 이 상황에서 자아를 포착하는 것처럼 보이지 않습니다. 코드를 제외 할 때 코드가 여전히 충돌합니까?

btw, 나는 당신의 질문에 당신이 그것을 단순화하려고 할 때 당신의 method1 구현이 좀 지저분하다고 생각합니다.

- (void) method1: (void(^)(NSMutableArray *a)) completionBlock withFailedBlock:(void(^)(NSInteger errorCode,NSString *error)) failedBlock { 
    ... 
} withFailedBlock:^(NSInteger errorCode, NSString *error) { 
    ... 
}]; 

유효한 메소드 구현처럼 보이지 않습니다.

- (void) method1: (void(^)(NSMutableArray *a)) completionBlock withFailedBlock:(void(^)(NSInteger errorCode,NSString *error)) failedBlock { 
    ... 
} 
관련 문제