2012-11-13 2 views
0


블록 및 약한 참조와 관련된 문제가 발생했습니다. ARC를 사용하고 있습니다. Google Directions API를 둘러싼 간단한 래퍼 인 무료 프로젝트입니다. 여기에서 다운로드 할 수 있습니다. link to the project
보기 컨트롤러에서 사용하고 있습니다. 사용 후보기 컨트롤러가 문제가되지 않습니다. 할당이 취소되었습니다. 나는이 객체에 문제가 있다고 생각한다. 왜냐하면 내가 주석 처리하거나 nil로 설정하면 모든 것이 올바르게 동작하기 때문이다.블록 및 유지주기가 catch 할 수 없습니다.

- (void) getDirections{ 
__weak RouteMapViewController * weakSelf = self; 
self.routeObject = [[RouteDirectionsObject alloc]init]; 

[self.mapView removeAnnotations:self.mapView.annotations]; 
[self.mapView removeOverlays:self.mapView.overlays]; 
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; 
[_routeObject createDirectionRequestWithStartPoint:weakSelf.startPoint 
              andEndPoint:weakSelf.endPoint 
            withCallBackBlock:^(NSError *error, NSDictionary *routeDistance, NSDictionary *routeDuration, MKPolyline *routePolyline, NSArray *routes, NSArray *steps, CLLocation *startPoint, CLLocation *endPoint, NSArray *directions) { 
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; 
    Annotation * startAnnotation = [[Annotation alloc]initWithCoordinate:startPoint.coordinate title:NSLocalizedString(@"YOUR_POSITION_KEY", @"Your position") annotationType:AnnotationTypeStart]; 
    Annotation * endAnnotation = [[Annotation alloc]initWithCoordinate:endPoint.coordinate title:NSLocalizedString(@"AIRPORT_POSITION_KEY", @"Airport position") annotationType:AnnotationTypeEnd]; 
    NSArray * annotationArray = [NSArray arrayWithObjects:startAnnotation, endAnnotation, nil]; 
    weakSelf.routeSteps = steps; 
    weakSelf.routeDirections = directions; 
    weakSelf.duration = routeDuration; 
    weakSelf.distance = routeDistance; 
    CLLocationDegrees maxLat = -90.0f; 
    CLLocationDegrees maxLon = -180.0f; 
    CLLocationDegrees minLat = 90.0f; 
    CLLocationDegrees minLon = 180.0f; 

    for (int i = 0; i < weakSelf.routeSteps.count; i++) { 
     NSDictionary * stepDictCoordinate = [[weakSelf.routeSteps objectAtIndex: i]objectForKey:@"start_location"]; 
     CLLocationCoordinate2D currentLocationCoordinate = CLLocationCoordinate2DMake([[stepDictCoordinate objectForKey:@"lat"]doubleValue], [[stepDictCoordinate objectForKey:@"lng"]doubleValue]); 
     if(currentLocationCoordinate.latitude > maxLat) { 
      maxLat = currentLocationCoordinate.latitude; 
     } 
     if(currentLocationCoordinate.latitude < minLat) { 
      minLat = currentLocationCoordinate.latitude; 
     } 
     if(currentLocationCoordinate.longitude > maxLon) { 
      maxLon = currentLocationCoordinate.longitude; 
     } 
     if(currentLocationCoordinate.longitude < minLon) { 
      minLon = currentLocationCoordinate.longitude; 
     } 
    } 

    MKCoordinateRegion region; 
    region.center.latitude  = (maxLat + minLat)/2; 
    region.center.longitude = (maxLon + minLon)/2; 
    region.span.latitudeDelta = maxLat - minLat; 
    region.span.longitudeDelta = maxLon - minLon; 


    dispatch_async(dispatch_get_main_queue(), ^{ 
     if (error) { 
      UIAlertView * alert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"Error", @"Error alert view title") message:NSLocalizedString(@"KEY_DIRECTIONS_ERROR", @"Alert error message for directions") delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
      [alert show]; 

      [_routesButton setEnabled:NO]; 

     } 
     else{ 
      [weakSelf.mapView addAnnotations:annotationArray]; 
      [_routesButton setEnabled:YES]; 

      if(routePolyline){ 
       [weakSelf.mapView addOverlay:routePolyline]; 
      } 
      else{ 
       UIAlertView * alert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"Error", @"Error alert view title") message:NSLocalizedString(@"KEY_DIRECTIONS_POLYLINE_ERROR", @"Polyline inconsistant") delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
       [alert show]; 

      } 
      //[weakSelf.mapView setRegion:region animated:YES]; 
      [weakSelf setRegion:region]; 
     } 
    }); 
}];} 

내가 넣으면 중단 점 및 뷰에 대한 질문 : 나는 약한 자기로 설정 물론, 유지 사이클입니다 이해할 수 아니에요, 여기에 내가 그것을 사용하는 뷰 컨트롤러의 방법입니다 컨트롤러의 retainCount보기 컨트롤러가 전달 된 경우에도 다른 시간이 증가하는 것을 볼 수 있습니다 약한. 도움이 될 것입니다.
감사합니다,
안드레아

/* ** * ** * ** * **UPDATE* ** * ** 을 * ** * */**
할당 확인 블록 내부에서 -tryRetain이라는 메서드를 통과 할 때까지 뷰 컨트롤러가 계속 유지되는 것을 볼 수 있지만 할당 해제를 위해 하나의 릴리스가 누락 된 것처럼 보입니다. 전달 된 블록이 클래스 경로 방향 객체에 복사되도록 지정해야합니다. 여기에서 다운로드 할 수있는 작은 샘플을 만들었습니다. download project

+0

는 또한 자기 클래스, 예를 들어 _routerButton의 (블록) 인스턴스 변수를 사용하지 말아야합니다 귀하의 경우 자체 클래스, _routerButton의 (블록) 인스턴스 변수를 사용할 수 없습니다. – NeverBe

+0

OMG ... 여기서 두 개의 _routeButton 인스턴스에 주석 처리가되어 있습니다. 모든 인스턴스가 올바르게 할당 해제됩니다. 단일 인스턴스로 복사 된 것 같습니다. 내가 그것을 확인하는 대답으로 써주세요. 정말 고맙습니다. – Andrea

답변

-1

당신은

+0

Thanks mate !!!! – Andrea

+1

** 당신이 할 수없는 이유에 대한 정보를 제공 할 수 있습니까? – WDUK

+0

@WDUK http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/Blocks/Articles/bxVariables.html – NeverBe

0

인스트루먼트를 사용하여 오브젝트를 유지하고 해제하고 무엇이 불균형이 발생하는지 파악할 수 있습니다. 이것은 프로젝트를 빌드하고 실행할 때 프로필을 선택하면 수행 할 수 있습니다. 그러면 장비가 부팅됩니다.

한 번 누출을 선택하여 누수가 발생한 위치를 확인할 수 있습니다. enter image description here

당신이 악기의 입씨름을하는 데 사용할 수있는 가이드 몇은 다음과 같습니다

+0

감사합니다. WDUK, 불행히도 변경되지 않습니다. R.C. 물체를 입력하기 전에 1의 RC가 있고, 나오면 6이됩니다. – Andrea

+0

인스트루먼트에 유지되는 것을 추적하려고 했습니까? 유지 및 릴리스 위치를 확인한 다음 불균형이 발생한 위치를 찾을 수 있습니까? 이 접근 방식을 반영하여 대답을 업데이트합니다. – WDUK

+0

확실히, 그것은 대단합니다 .. 객체의 RC 역사에서 명확하게 볼 수 있습니다 블록 안에 들어가서 많은 증분을받습니다. 수동으로 얻을 수있는 참조 카운트가 누설 된 것과 다릅니다. – Andrea

1

객체의 절대 유지 카운트 의미가; www.whentouseretaincount.com (기술 세부 사항을 설명하는 하단에 몇 가지 링크가 있음).

누수 계기가 도움이 될 것 같지 않습니다. 그것은 가능할 수도 있지만 그렇지 않을 수도 있습니다. Allocations Instrument는 귀하의 친구입니다. "레코드 참조 횟수"및 "활성 할당 만 추적"을 켭니다. 인스트루먼트에서 앱을 실행 한 다음 사라져야 할 대상을 찾으십시오. 어느 하나를 클릭하면 해당 오브젝트의 보유/릴리스 이벤트가 표시되어 추가 보유가 어디에서 오는 것인지에 대한 질문에 응답합니다.

이것은 뷰 객체이기 때문에 여전히 뷰 계층 구조에 있지만 다른 불투명 뷰 뒤에 묻어 있기 때문일 수 있습니다. 또한 타이머의 대상이나 캐시에서 잠재적으로 "돌아 가기"스타일 탐색 캐시로 유지 될 수 있습니다.

+0

안녕하세요, 감사합니다. 할당을 사용하여 프로젝트를 확인한 결과, 뷰 컨트롤러가 메서드를 입력하는 데 많은 시간을 사용할 것으로 보이고, 메서드에 -tryRetain 및 이벤트와 관련된 다른 메서드를 호출하는 스택을 명확하게 볼 수 있습니다. 뷰 컨트롤러를 보유하고있는 다른 개체를 확인하기 위해 예제 프로젝트로 응답을 업데이트했습니다. 보시다시피 맵을 경로를 통해 볼 컨트롤러를 밀어 넣으면 탐색 컨트롤러 스택 내부에 참조가없는 경우에도 팝업이 해제되지 않습니다. – Andrea

관련 문제