MKMapView memory usage gets out of control with setRegion: calls

I have one instance MKMapViewthat I programmatically added to UIView. Within the user interface, the user can iterate over the list of addresses, and the map display is updated to show the correct map for each address when the user goes through them. I create a map view once and just change what it displays with setRegion:animated.

The problem is that every time the card is changed to display a new address, the use of my program in memory increases by 200K-500K (as reported by Memory Monitor in Instruments). According to Object Allocations, it seems that a lot of 1.0K Mallocs happen every time, and the Extended Detail panel for these 1.0K distributions shows that the Responsible Caller is convert_image_data, and the Extended Detail panel shows that this is the result[MKMapTileView drawLayer:inContext:]. Therefore, it seems to me that the use of memory is due to the fact that MKMapView does not free the memory that it uses to redraw the map each time. In fact, when I don’t show the map at all (without even adding it as a subtitle of my main UIView), but still look through the addresses (which changes various UILabels and other displayed information), do NOT increase the memory usage for the application. If I add a map view but never update it with setRegion :, the memory also DOES NOT increase when changing to a new address.

Another bit of information: if I switch to a new address (and therefore ask the card to display the new address), a memory jump will be described above. However, if I return to an address that has already been mapped, the memory does not jump when the map is redrawn with the old address. In addition, this happens on the iPad (real device) with 3.2 and on the iPhone (again, on the real device) with 3.1.2.

This is how I initialize 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, choosing the address, I install the card as follows:

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 combed the web, but did not see any mention of this problem, and I reached the limits of my knowledge. Thanks for any ideas.

+3
source share
1 answer

, ? ?

, , , , , .

0

Source: https://habr.com/ru/post/1746927/


All Articles