나는 매우 복잡한 웹 서비스 세트를 끓여서 간단한 코드로 검색합니다. 검색 (또는 아래 버튼의 클릭에 대한 샘플)에 대한 응답으로지도에 주석을 추가 할 수 있어야하고, 사용자가 버튼을 다시 클릭하여 새로운 결과 세트를 얻을 수 있어야합니다. 실제로는 다른 숫자가 있지만 단순화 된 예제에서는 항상 주석을 맵뷰에 추가합니다. 내 코드에서 기존 주석을 제거하고 새 주석을 추가해야한다고 생각하지만 두 번째 및 후속 버튼을 누를 때 32 바이트가 누수됩니다. 내가 무엇이 누락 되었습니까? (또는 케이스로 유지하는 단계 일 수있다!)MKMapView 주석을 제거하면 누출이 발생합니다.
testViewController.h
#import <UIKit/UIKit.h> #import <MapKit/MapKit.h> #import "MyMark.h" @interface testViewController : UIViewController { MKMapView *mapView; } @end
testViewController.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { // Custom initialization [email protected]"test"; } return self; } - (void) storeLocationInfo: (CLLocationCoordinate2D) loc title:(NSString *)t subtitle:(NSString *)st index:(int)i { NSArray * annotations = [mapView annotations]; [mapView removeAnnotations:annotations]; MyMark * mymark=[[MyMark alloc] initWithCoordinate:loc]; [mapView addAnnotation:mymark]; [MyMark release]; } - (void)viewDidLoad { [super viewDidLoad]; UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:@"Add point to map" style:UIBarButtonItemStylePlain target:self action:@selector(addPushed)]; [self.navigationItem setRightBarButtonItem:barButton]; [barButton release]; mapView=[[MKMapView alloc] initWithFrame:CGRectMake(0.0,0.0,self.view.frame.size.width,self.view.frame.size.height)]; mapView.showsUserLocation=FALSE; mapView.delegate=self; [self.view insertSubview:mapView atIndex:0]; [mapView release]; } - (void) addPushed { MKCoordinateRegion reg = mapView.region; [self storeLocationInfo:reg.center title:@"price" subtitle:@"title" index:1]; } - (void)dealloc { [super dealloc]; }
MyMark.h
#import <Foundation/Foundation.h> #import <MapKit/MapKit.h> @interface MyMark : NSObject<MKAnnotation> { CLLocationCoordinate2D coordinate; NSString * title; NSString * subtitle; int index; } @property (nonatomic, readonly) CLLocationCoordinate2D coordinate; @property (nonatomic, readonly) int index; @property (nonatomic, retain) NSString * title; @property (nonatomic, retain) NSString * subtitle; -(id)initWithCoordinate:(CLLocationCoordinate2D) coordinate; -(id)setCoordinate:(CLLocationCoordinate2D) coordinate; -(id)setTitle:(NSString *)t subtitle:(NSString *)st index:(int)i ; @end
에게 MyMark.m
#import "MyMark.h" @implementation MyMark @synthesize coordinate, index; @synthesize title,subtitle; -(id)initWithCoordinate:(CLLocationCoordinate2D) c{ coordinate=c; NSLog(@"%f,%f",c.latitude,c.longitude); return self; } -(id)setCoordinate:(CLLocationCoordinate2D) c{ coordinate=c; NSLog(@"%f,%f",c.latitude,c.longitude); return self; } -(id)setTitle:(NSString *)t subtitle:(NSString *)st index:(int) i{ self.title=t; self.subtitle=st; index=i; return self; } -(void) dealloc { [title release]; [subtitle release]; [super dealloc]; }
당신이 옳습니다. 자기 머리를 때린다. 아주 열심히. – Andiih