2011-11-13 3 views
0

NSURLConnection 대리자 메서드 connectionDidFinishLoading이 실행되는 동안 오류가 발생했습니다. 흥미롭게도 시뮬레이터에서 작동하지만 실제 장치에서 충돌합니다.connectionDidFinishLoading에서 수신 오류, EXC_BAD_ACCESS

  • 실행 앱
  • , 그것은 작업의 순서가 수행 된 경우에만 충돌이 더 흥미롭게도이 트윗을 보여줍니다!
  • 을 눌러 홈 버튼 (최고)
  • 더블 클릭 홈 버튼
  • 강제
  • 추락 열려있는 응용 프로그램 다시 응용 프로그램
  • 을 종료 !!!!! 당신이 휴대 전화를 다시 시작할 때까지 (:() ... 충돌 유지

오류 로그!

Exception Type: EXC_BAD_ACCESS (SIGSEGV) 
Exception Codes: KERN_INVALID_ADDRESS at 0xa0000008 
Crashed Thread: 0 

Thread 0 name: Dispatch queue: com.apple.main-thread 
Thread 0 Crashed: 
0 libobjc.A.dylib     0x321befbc 0x321bb000 + 16316 
1 Tittle-Tattle     0x0002cf10 -[MapViewController connectionDidFinishLoading:] (MapViewController.m:108) 
2 Foundation      0x3316bc32 0x330a5000 + 814130 
3 Foundation      0x330c36e2 0x330a5000 + 124642 
4 Foundation      0x330c36ac 0x330a5000 + 124588 
5 Foundation      0x330c35ce 0x330a5000 + 124366 
6 CFNetwork      0x35e7689e 0x35e67000 + 63646 
7 CFNetwork      0x35e6b53e 0x35e67000 + 17726 
8 CFNetwork      0x35e6b632 0x35e67000 + 17970 
9 CFNetwork      0x35e6b23c 0x35e67000 + 16956 
10 CFNetwork      0x35e6b172 0x35e67000 + 16754 
11 CoreFoundation     0x34176afc 0x340e9000 + 580348 
12 CoreFoundation     0x341762c8 0x340e9000 + 578248 
13 CoreFoundation     0x3417506e 0x340e9000 + 573550 
14 CoreFoundation     0x340f84d6 0x340e9000 + 62678 
15 CoreFoundation     0x340f839e 0x340e9000 + 62366 
16 GraphicsServices    0x3254dfc6 0x3254a000 + 16326 
17 UIKit       0x3734e73c 0x3731d000 + 202556 
18 Tittle-Tattle     0x000200e0 main (main.m:16) 
19 Tittle-Tattle     0x00020084 start + 32 

CODE :

- (void)connectionDidFinishLoading:(NSURLConnection *)connection { 

    [urlConnection cancel]; 
    [urlConnection release]; 
    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 

    //Since we got new fresh data we shall put it in LatestLocationData entity in CoreData 
    [self insertLastKnownLocationDataIntoCoreDataWith:responseString]; 

    //Test purpose only, See what we have got in CoreData 
    [self fetchLastKnownLocationDataFromCoreData]; 

    NSDictionary *results = [responseString JSONValue]; 
    placesNearBy = [results objectForKey:@"results"]; 

    [responseString release]; 

    [self dropNearByPlacesAnnotationsFrom:placesNearBy]; 

} 

질문 : 가능한 수 무엇 그 이유는 무엇입니까?

(! 아니 내게로) 10

비슷한 질문 이전에 요청했지만 아무도 그 질문에 대답하지 : Application not running in iOS 5


나의 이해 당신이하지 않은 메모리 주소를 액세스하려고하면 지금까지이며, EXE_BAD_ACCESS 만 발생 할당되었거나 이전에 할당되었지만 이제는 릴리스되었습니다. COMMENT IN 응답 AFTER

편집 :

헤이 Firoze는, 이것은 내가있는 NSURLConnection

urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 
+0

에게 @FirozeLafeer 안녕 메이트! 나는 init 메소드를 추가했다. 질문 :) 감사. 나는 alloc이고 init은 같은 함수이기 때문에 NSString을 거기에서 공개하고있다. 나는 그것을 풀어야한다고 생각한다. 그렇다. 그렇지 않으면 – doNotCheckMyBlog

+0

어디에서 오는 responseData가 유출됩니까? 그것이 생성되는 곳마다 보존됩니까? – coneybeare

+0

@Brogrammer는 responseString에 대한 저의 의견을 무시합니다. 신경 쓰지 마, 나는 거기에서 똑바로 생각하지 않고 있었다. 나는 그 부분을 놓쳤다. –

답변

3

나는 당신이 당신의 인스턴스 변수의 모든 @property 선언을 사용하는 것이 좋습니다 것입니다 귀하의 의견을 보면 init을하고 방법이다. 사용자가해야하는 수동 메모리 관리를 모두 완화 할 수 있습니다. 이는 문제가있는 곳일 것입니다.

빠른 예를

YourClass.h

@interface YourClass 
@property (nonatomic, retain) NSURLConnection *urlConnection; 
// More ivars 

// Method declations 
@end 

YourClass.m

@interface YourClass 

@synthesize urlConnection = _urlConnection; 

// The method where you instantiate urlConnection 
{ 
    NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:request 
                    delegate:self]; 
    self.urlConnection = urlConnection; 
    [urlConnection release]; urlConnection = nil; 

    // Do whatever else you do here 
} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    [self.urlConnection cancel]; 
    self.urlConnection = nil;  <- This takes care of releasing the ivar and setting it to nil so there is no dangerous hanging pointer 

    // ... the rest of your method 
} 

[urlConnection cancel]; 
[urlConnection release]; 
// You need to clean up after yourself with any ivars you make 
- (void)dealloc 
{ 
    [_urlConnection release]; 
    // Release any other ivars 
    [super dealloc]; 
} 
@end 
+0

방금 ​​내 dealloc 및 viewDidUnload를 체크 한 한가지 더 말한 적이 있습니까? 이게 특이한가요? dealloc에서 내 모든 릴리스 방법은 낭비라고 생각합니다. ( – doNotCheckMyBlog

관련 문제