2011-01-17 4 views
1

DisplayMap.h누군가이 코드에서 누수를 가리킬 수 있습니까?

#import <Foundation/Foundation.h> 
#import <MapKit/MKAnnotation.h> 


@interface DisplayMap : NSObject <MKAnnotation> { 

    CLLocationCoordinate2D coordinate; 
    NSString *title; 
    NSString *subtitle; 
} 
@property (nonatomic, assign) CLLocationCoordinate2D coordinate; 
@property (nonatomic, copy) NSString *title; 
@property (nonatomic, copy) NSString *subtitle; 

@end 

DisplayMap.m

#import "DisplayMap.h" 


@implementation DisplayMap 

@synthesize coordinate,title,subtitle; 


-(void)dealloc{ 
    [title release]; 
    [super dealloc]; 
} 

@end 

내가 주석을 보여 맵보기에서 위를 구현하고있다. viewdidload에서 좌표 집합을 통해 실행하고 위에서 언급 한 주석 클래스를 사용하여지도에 표시합니다. 누수 악기를 실행

for(int i=0;i<[xmlParameter count];i++){ 
    region.center.latitude=(double)[[[xmlParameter objectAtIndex:i]objectAtIndex:3] doubleValue]; 
    region.center.longitude =(double) [[[xmlParameter objectAtIndex:i]objectAtIndex:4] doubleValue] ; 
    region.span.longitudeDelta = 0.08f; 
    region.span.latitudeDelta = 0.08f; 
    DisplayMap *ann = [[DisplayMap alloc] init]; 
    ann.title = [[xmlParameter objectAtIndex:i]objectAtIndex:0]; 
    ann.subtitle = [[xmlParameter objectAtIndex:i]objectAtIndex:1]; 
    ann.coordinate = region.center; 
    [mapView addAnnotation:ann]; 
    if(i==zoomtoParameter){ 
     [mapView setRegion:region animated:YES];    
     //showAnnotation=ann;  
     [mapView selectAnnotation:currentAnnotation animated:YES];   
     //[mapView selectAnnotation:ann animated:YES]; 
    } 

    [ann release]; 
} 

의 viewDidLoad에 방법에 32 바이트의 DisplayMap 누출이 말했다. 나는 방법을 이해할 수 없다. 그것으로 끝나면 DisplayMap 객체를 발표 할 것입니다.

제안 사항?

감사

+0

'dealloc'에서도'subtitle'을 풀어보십시오. – Mahesh

+0

제목을 공개했는데 어디에서 할당 했습니까? –

답변

4

귀하의 subtitle 속성은 당신이 그것을 해제 할 책임이 있습니다 의미 copy 속성으로 선언됩니다. 당신의 dealloc 방법을 다음과 같이 변경 트릭을 수행해야합니다

-(void)dealloc{ 
    [subtitle release]; 
    [title release]; 
    [super dealloc]; 
} 

편집 :가 정교하게하려면 : 당신이 어떤 메모리를 release합니다 코코아의 memory management 규칙 상태 당신 alloc, retain 또는 copy. 합성 속성의 경우 이는 -dealloc 방법에 적절한 release 개의 메시지를 포함해야 함을 의미합니다. 자세한 내용은이 항목에서 내 자신의 question을 참조하십시오. 제공된 샘플 코드에서

, 다음 줄은 :

ann.subtitle = [[xmlParameter objectAtIndex:i]objectAtIndex:1]; 

는 표시 객체의 복사본을 생성합니다. 나중에 [ann release]으로 전화하면 명시 적으로 해제하지 않으면 복사 된 개체가 유출됩니다.

+0

'[ann release];는 모든 멤버 변수의 할당을 해제합니까? – Mahesh

+0

eJames가 맞습니다. [super dealloc]을 그리워 할 때 경고를 받는다. . 경고를 받으면 그것을 해결하십시오 : – nacho4d

+0

@Mahesh :'-dealloc' 메쏘드는 객체의 수명 기간 중 어느 시점에서 할당되었거나, 유지되거나 복사 된 (아직 릴리즈되지 않은) 멤버 변수를 릴리즈 할 책임이 있습니다. –

관련 문제