iPhone mapView / mapKit using removeAnnotation & addAnnotation results in memory leak?
- by user266618
To update the location of a GPS indicator on mapView...
[mapView removeAnnotation:myGpsAnnotation];
[myGpsAnnotation release];
myGpsAnnotation = nil;
myGpsAnnotation = [[MapLocationAnnotation alloc] initWithCoordinate:region.center annotationType:MapAnnotationTypeGps title:MAP_ANNOTATION_TYPE_GPS];
[mapView addAnnotation:myGpsAnnotation];
...I see net memory slowly climbing in Instruments (simulator). No "Leak" blip, but "Net Bytes" and "# Net" slowly incrementing... unless this code is commented out. So I'm 100% certain this is the offending code.
BUT if I do the following...
[mapView removeAnnotation:myGpsAnnotation];
[myGpsAnnotation release];
myGpsAnnotation = nil;
myGpsAnnotation = [[MapLocationAnnotation alloc] initWithCoordinate:region.center annotationType:MapAnnotationTypeGps title:MAP_ANNOTATION_TYPE_GPS];
[mapView addAnnotation:myGpsAnnotation];
[mapView removeAnnotation:myGpsAnnotation];
[mapView addAnnotation:myGpsAnnotation];
[mapView removeAnnotation:myGpsAnnotation];
[mapView addAnnotation:myGpsAnnotation];
...then the "Net Bytes" and "# Net" increase much faster. Is it possible this isn't my mistake, and I'm trying to track down a leak in MapKit? Am I really leaking memory? Again, nothing appears under "Leaks", but then I don't see why Net values would be continually climbing.
Thanks for any help, -Gord