2014-06-11 3 views
0

안녕하세요 프로젝트에 파일에서 더미 데이터를 얻을이 기능이 있습니다 문제는 그 라인에 나와 있습니다잠재적 인 누출

NSString *path = [[NSBundle mainBundle] pathForResource: @"StatisticsDataJSON" ofType: @"TXT"]; - 객체의 잠재적 누출. 의 전위 누설 - 'statisticArray'

for (int i = 0; i < statsForDate.count; i++) {에 저장된 물체의 전위 누설 -

NSMutableDictionary *statisticsResponse = [jsonParser objectWithString:data];는 - 'jsonParser'

for (id key in statisticsResponse) {에 저장된 물체의 잠재적 누출 's'에 저장된 객체

if (self.statistics==nil) 
{ 
    self.statistics = [[NSMutableDictionary alloc]init]; 
    NSString *path = [[NSBundle mainBundle] pathForResource: @"StatisticsDataJSON" ofType: @"TXT"]; 
    NSError *error = nil; 
    NSString *data = [NSString stringWithContentsOfFile: path 
              encoding: NSUTF8StringEncoding 
               error: &error]; 
    //NSLog(@"%@",data); 

    SBJsonParser *jsonParser = [[SBJsonParser alloc] init]; 
    NSMutableDictionary *statisticsResponse = [jsonParser objectWithString:data]; 

    for (id key in statisticsResponse) { 
     NSArray *statsForDate = [statisticsResponse objectForKey:key]; 
     NSMutableArray *statisticArray = [[NSMutableArray alloc]init]; 
     for (int i = 0; i < statsForDate.count; i++) { 
      Statistic *s = [[Statistic alloc]init]; 
      s.locationId = [[statsForDate objectAtIndex:i] objectForKey:@"locationId"]; 
      int value =[[[statsForDate objectAtIndex:i] objectForKey:@"visits"] integerValue]; 
      s.visits = value; 
      value =[[[statsForDate objectAtIndex:i] objectForKey:@"totalUsers"] integerValue]; 
      s.totalUsers = value; 
      value= [[[statsForDate objectAtIndex:i] objectForKey:@"uploads"] integerValue]; 
      s.uploads = value; 
      value = [[[statsForDate objectAtIndex:i] objectForKey:@"downloads"] integerValue]; 
      s.downloads = value; 
      value = [[[statsForDate objectAtIndex:i] objectForKey:@"apps"] integerValue]; 
      s.apps = value; 
      [statisticArray addObject:s]; 
     } 
     [self.statistics setObject:statisticArray forKey:key]; 
    }; 
} 
-

내가 ststisticsResponse에서 그 오토 릴리즈를 발견 한 문제 해결 :

NSMutableDictionary *statisticsResponse = [[jsonParser objectWithString:data]autorelease]; 

을하지만 뭔가 dealoc 기능에 SBJsonStreamParserAccumulator.m에 실패합니다.

무엇이 문제인가? 즉, 참조 된 개체가 기술적으로 "유출"되는 첫 번째 점 때문에 잠재적 인 누출에 대한 경고, 잠재적 누출 다음 줄 에 올

+0

ARC를 사용하지 않습니까? – borrrden

+0

이전 프로젝트 - ARC가 아님 – Cheese

+1

업데이트하는 것이 좋습니다. 그것을 본 사람은 메모리 관리에 대해 전혀 모른다. 그것 또는 당신은 전체 그림을 보여주지 않습니다. 나중에 배포해야하는 모든 것을 alloc/init합니다. 그거하고 있니? – borrrden

답변

0

참고. 따라서 현재 수정 된 내용이 과도하게 공개되어 충돌을 일으킬 수 있습니다.

귀하의 질문의 첫 번째 문은 실제로 직전,이 라인의 누출을 의미한다 : 당신은 할당 된 사전을 더 이상 참조가있어

self.statistics = [[NSMutableDictionary alloc]init]; 

, 당신은 그래서 그것이 보관 된 재산이다 누출.

self.statistics = [[[NSMutableDictionary alloc]init] autorelease]; 

해결할 것입니다. (구문 분석이를 완료 한 후 ) 당신이 그것으로 마친 다음 하나, 당신은 jsonParser를 해제해야한다 : 나는 그들 모두를 통과하지 않을거야하지만 당신은 얻을해야

[jsonParser release]; 

생각. 기본적으로 메모리 관리 가이드를 읽거나 ARC로 업데이트해야합니다.

경고의 변수 이름에주의하십시오. 누출 위치를 알려줍니다.

+0

감사합니다. 전에 self.statistics를 제외한 모든 누수를 처리 한 답을 보았습니다. 그리고 당신의 대답이 나의 마지막 문제를 해결했습니다. =) – Cheese

관련 문제