2012-03-13 3 views
0

좀비를 나타내는이 오류가 계속 발생합니다. 나는이 두 가지 방법으로 그 범위를 좁혔지만, 나 자신의 삶은 잘못된 것을 알아낼 수 없다.[CFDictionary release] : 할당 취소 된 인스턴스로 전송 된 메시지, 무엇이 잘못 되었나요?

아이디어가 있으십니까?

-(void) getWeatherDetail: (NSString *)query 
{ 
    @try 
    { 
     NSString *urlString111 = [NSString stringWithFormat:@"http://www.google.com/ig/api?weather=%@",query]; 
     urlString111 = [urlString111 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
     NSURL *url = [NSURL URLWithString:urlString111]; 

     NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; 

     NSData *returnData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil]; 

     if(xmlParser) 
     { 
      xmlParser=nil; 
      [xmlParser release]; 

     } 


     xmlParser = [[NSXMLParser alloc] initWithData: returnData]; 
     isForeCast = NO; 
     isFirstForeCastEnd = NO; 
     if (!self.arrForecastAll) { 
      self.arrForecastAll = [[NSMutableArray alloc] init]; 
     } 
     [self.arrForecastAll removeAllObjects]; 
     [xmlParser setDelegate: self]; 
     [xmlParser setShouldResolveExternalEntities: YES]; 
     [xmlParser parse]; 

//  self.logString = [NSString stringWithFormat:@"%@Date & Time: %@ | Text: Getting Weather detail.\n", self.logString, [NSDate date]]; 
//  [self updateLogFile:self.logString]; 
    } 
    @catch (NSException *exception) { 
     NSLog(@"Ad exc %@",[exception description]); 
    } 
    @finally { 

    } 
} 

그리고이 하나

..

-(void)getCurrentCityName 
{ 
    //////Method to find current city name 
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
    @try 
    { 
     if ([self.arrSettings count] > 0 && [[[self.arrSettings objectAtIndex:3] objectForKey:@"Value"] isEqualToString:@"Current Location"]) 
     { 
      if (currentlat != 0 && currentlong != 0) { 
       NSURL *urlString; 




       NSLog(@"lat %f %f" ,currentlat,currentlong); 
       urlString =[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.google.com/maps/geo?output=json&oe=utf-8&ll=%f,%f&key=[removed API key]",currentlat,currentlong]]; 



       NSLog(@"\n\n-------------------------TF-Get City Name -Request-----------------------------\n%@\n\n",urlString); 
       NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ; 

       [request setURL:urlString]; 
       NSData *returnData = [ NSURLConnection sendSynchronousRequest: request returningResponse:nil error: nil ]; 
       NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; 

       NSLog(@"\n\n------------------------TF-Get City Name -Response------------------------\n\n%@\n\n",returnString); 


       [request release]; 
       NSDictionary *dictAddress=[returnString objectFromJSONString]; 
       NSLog(@"dictAddress %@",[dictAddress description]); 

       [returnString release]; 

       NSString *strCity = [NSString stringWithFormat:@"Getting Location"]; 
       NSLog(@"strCity %@",strCity); 
       if ([[dictAddress allKeys] count] > 1) 
       { 

        if ([[[[[[dictAddress valueForKey:@"Placemark"] objectAtIndex:0] valueForKey:@"AddressDetails"] valueForKey:@"Country"] valueForKey:@"AdministrativeArea"] valueForKey:@"SubAdministrativeArea"]) 
        { 
         strCity = [NSString stringWithFormat:@"%@,%@", 
            [[[[[[[[dictAddress valueForKey:@"Placemark"] objectAtIndex:0] valueForKey:@"AddressDetails"] valueForKey:@"Country"] valueForKey:@"AdministrativeArea"] valueForKey:@"SubAdministrativeArea"] valueForKey:@"Locality"] valueForKey:@"LocalityName"], 
            [[[[[[dictAddress valueForKey:@"Placemark"] objectAtIndex:0] valueForKey:@"AddressDetails"] valueForKey:@"Country"] valueForKey:@"AdministrativeArea"] valueForKey:@"AdministrativeAreaName"]]; 
        } 
        else { 
         strCity = [NSString stringWithFormat:@"%@,%@", 
            [[[[[[[dictAddress valueForKey:@"Placemark"] objectAtIndex:0] valueForKey:@"AddressDetails"] valueForKey:@"Country"] valueForKey:@"AdministrativeArea"] valueForKey:@"Locality"] valueForKey:@"LocalityName"], 
            [[[[[[dictAddress valueForKey:@"Placemark"] objectAtIndex:0] valueForKey:@"AddressDetails"] valueForKey:@"Country"] valueForKey:@"AdministrativeArea"] valueForKey:@"AdministrativeAreaName"]]; 
        } 

        self.strCurrentCity = strCity; 
        [self getWeatherDetail:self.strCurrentCity]; 
       } 

      } 
      else 
      { 
       self.strCurrentCity = @"Current Location"; 
      } 

     } 
     else 
     { 
      self.strCurrentCity = [[self.arrSettings objectAtIndex:3] objectForKey:@"Value"]; 
      [self getWeatherDetail:self.strCurrentCity]; 
     } 

//  self.logString = [NSString stringWithFormat:@"%@Date & Time: %@ | Text: Getting current city name. CityName: %@\n", self.logString, [NSDate date], self.strCurrentCity]; 
//  [self updateLogFile:self.logString]; 


     [pool release]; 
    } 
    @catch (NSException *exception) { 
     NSLog(@"Ad exc %@",[exception description]); 
    } 
    @finally { 

    } 
} 
+1

어떤 라인이 충돌합니까? –

+0

당신은'objectFromJSONString' 메쏘드의 구현을 게시 할 수 있습니다 ... 그리고 incarna는 한 줄짜리 코딩 스타일을 피하기 때문에 읽기가 어렵습니다. 네가 부셔 버릴 수 있다면 .. –

답변

2

이것은 당신이 직접 바르 액세스에 의해 얻을 고전적인 메모리 관리 문제입니다. 접근자를 사용하여 ivars를 처리하면 코드가 더 간단 해지고 이러한 종류의 버그가 발생하지 않습니다. 와

if(xmlParser) 
    { 
     xmlParser=nil; 
     [xmlParser release]; 
    } 

    xmlParser = [[NSXMLParser alloc] initWithData: returnData]; 
    isForeCast = NO; 
    isFirstForeCastEnd = NO; 
    if (!self.arrForecastAll) { 
     self.arrForecastAll = [[NSMutableArray alloc] init]; 
    } 

:

self.xmlParser = [[[NSXMLParser alloc] initWithData: returnData] autorelease]; 
    self.isForeCast = NO; 
    self.isFirstCoreCastEnd = NO; 
    if (!self.arrForecastAll) { 
     self.arrForecastAll = [NSMutableArray array]; 
    } 

이것은 또한 arrForecastAll에 과제의 누출을 제거

그래서이 코드를 교체합니다.

두 번째 블록과 관련하여 변수가 release 일 때마다 변수가 즉시 범위를 벗어나지 않으면 항상 nil으로 설정해야합니다. 예를 들어, [request release] 뒤에 request = nil을 붙여야합니다.

그런데 왜이 모든 것을 @try 블록에 넣고 있습니까? ObjC의 예외 처리는 드물고 비용이 많이 들고 메모리 누수입니다. 예외는 일반적으로 ObjC에서 복구 할 수없는 오류를 나타내며 일반적인 오류 처리 시스템이 아닙니다. @try가 적절할 때가 있지만, 여기에는 어떤 이유도 보이지 않습니다.

관련 문제