I have the following simple code to track MKAnnotations in my MKMapView. I create the annotations in a loop through my list of locations I want to track. I add the annotations to my collection classes, an NSMutableDictionary and NSMutableArray, which are declared properties (not using ARC but am using Xcode 4.2 so using "strong" instead of retain since they are supposedly synonymous; for future compatibility with ARC).
If I call this routine a second time (say when the list of locations gets updated), the Leaks Instrument claims that the annotations are leaking, as well as the collection objects themselves. (I get a single NSMUtableDictionary in my leak list with the stack trace pointing to the line where the dictionary is created and set into my property, we well as a number of small leaks that match up to the annotations, and complaints about both the NSMutableArray and NSMutableDictionary). However, I don't see any violations of the memory management rules. I have a release paired with my annotation creation through alloc/init. I do an implicit retain through my property "setter" and when the collections are replaced, they should be released and then release all their content objects. If anyone can see where I go wrong, I would appreciate it.
@property(strong, nonatomic) NSMutableArray *annotationList;
@property(strong, nonatomic) NSMutableDictionary *annotationLocations;
.
-(void) createMapAnnotations
{
if ([[self mapView] annotations])
[[self mapView] removeAnnotations:[[self mapView] annotations]];
[self setAnnotationList:[NSMutableArray array]];
[self setAnnotationLocations:[NSMutableDictionary dictionary]];
for (JEstablishmentLocation *loc in [[JLocationManager sharedLocationManager] localLocations])
{
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
[annotation setCoordinate:[[loc estCoordinates] coordinate]];
[[self mapView] addAnnotation:annotation];
[[self annotationList] addObject:[NSDictionary dictionaryWithObject:annotation forKey:[loc estKeyValue]]];
[[self annotationLocations] setObject:loc forKey:[annotation description]];
[annotation release];
}
[self centerOnCurrentLocation];
}