Hi,
I have a single MKMapView instance that I have programmatically added to a UIView. As part of the UI, the user can cycle through a list of addresses and the map view is updated to show the correct map for each address as the user goes through them. I create the map view once, and simply change what it displays with setRegion:animated:.
The problem is that each time the map is changed to show a new address, the memory usage of my program increases by 200K-500K (as reported by Memory Monitor in Instruments). According to Object Allocations, it appears that a lot of 1.0K Mallocs are happening each time, and the Extended Detail pane for these 1.0K allocations shows that the Responsible Caller is convert_image_data and the Extended Detail pane shows that this is the result of [MKMapTileView drawLayer:inContext:]. So, seems likely to me that the memory usage is due to MKMapView not freeing memory it uses to redraw the map each time. In fact, when I don't display the map at all (by not even adding it as a subview of my main UIView) but still cycle through the addresses (which changes various UILabels and other displayed info) the memory usage for the app does NOT increase. If I add the map view but never update it with setRegion:, the memory also does NOT increase when changing to a new address.
One more bit of info: if I go to a new address (and therefore ask the map to display the new address) the memory jumps as described above. However, if I go back to an address that was already displayed, the memory does not jump when the map redraws with the old address. Also, this happens on iPad (real device) with 3.2 and on iPhone (again, real device) with 3.1.2.
Here's how I initialize the MKMapView (I only do this once):
CGRect mapFrame;
mapFrame.origin.y = 460; // yes, magic numbers. just for testing.
mapFrame.origin.x = 0;
mapFrame.size.height = 500;
mapFrame.size.width = 768;
mapView = [[MKMapView alloc] initWithFrame:mapFrame];
mapView.delegate = self;
[self.view insertSubview:mapView atIndex:0];
And in response to the user selecting an address, I set the map like so:
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=kStreetMapSpan; // 0.003
span.longitudeDelta=kStreetMapSpan; // 0.003
region.center = address.coords; // coords is CLLocationCoordinate2D
region.span = span;
mapView.region.span = span;
[mapView setRegion:region animated:NO];
Any thoughts? I've scoured the net but haven't seen mention of this problem, and I've reached the limits of my Instruments knowledge. Thanks for any ideas.