Saturday, February 25, 2012

MapView and dealloc IOS


Hello i have a mapView and i think it takes too much memory after leaving the mapView



here are my methods is anything missing?




- (void)viewDidUnload
{

mapView.showsUserLocation = NO; b
[mapView removeAnnotations:mapView.annotations];

[super viewDidUnload];

}


-(void)dealloc{
[name release];
[type release];
[address release];
mapView.delegate = nil;

[super dealloc];
}

- (void)viewDidLoad{
foundLocation = location found <----

MKCoordinateRegion region;
region.center.latitude = foundLocation.coordinate.latitude;
region.center.longitude=foundLocation.coordinate.longitude;
region.span.longitudeDelta=0.01;
region.span.latitudeDelta=0.01;
[mapView setRegion:region animated:NO];

ann = [[MapAnnotation alloc]init];
ann.title = name;
ann.subtitle = type;
ann.coordinate=region.center;
[mapView addAnnotation:ann];
[ann release];

self.navigationItem.title=@"Map";
[super viewDidLoad];
}



The map view also shows users location i think something is missing from the viewDidUnload method....



The MapAnnotation is a class that shows an annotation just holds a title and a subtitle.



i think the app keep tracking users location even if i leave the mapView.

1 comment:

  1. After you set the delegate to nil, you did not call [mapView release]

    ReplyDelete