我正在研究一个iPhone应用程序,该应用程序在某些位置显示带有多个圆形覆盖图的地图。 我遇到严重的内存问题和崩溃,当我添加超过6个圈子,我缩小足够远,他们都可见。 当我放大以至只有2个圆圈可见时,一切都很好。当我删除MKOverlays时,一切正常。MKMapView上的多个MKOverlays导致内存警告
任何人认识到这种行为?
创建叠加层的代码。我存储在一个的NSMutableDictionary的叠加以供将来参考(能够从地图上删除,并避免双重叠加),使覆盖观点,即释放
#pragma mark -
#pragma mark MKMapViewDelegate
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay{
MKCircleView *circleView = [[[MKCircleView alloc] initWithCircle:overlay] autorelease];
circleView.lineWidth = 1.0;
circleView.strokeColor = [UIColor redColor];
return circleView;
}
代码
- (void)updateMarkersForZones:(NSArray *)zones {
NSLog(@"MapViewController: Update Markers");
// For each zone, show a marker
for (Zone* zone in zones) {
NSString *keyMarker = [NSString stringWithFormat:@"%d-marker", zone.id];
MKCircle *circle = [overlayCache objectForKey:keyMarker];
if (circle == nil) {
// draw the radius circle for the marker
double radius = MAX(zone.markerRadius * 1.0, 1.0);
circle = [MKCircle circleWithCenterCoordinate:zone.location radius:radius];
[mapView addOverlay:circle];
// store the circle in a cache for future reference
[overlayCache setObject:circle forKey:keyMarker];
}
}
}
代码覆盖缓存
- (void)dealloc {
[overlayCache release];
[mapView release];
[super dealloc];
}
好奇这是发生在iOS版本。仪器在哪里看到内存消耗峰值? – Nick 2010-07-31 16:20:05
我正在运行iOS 4.0。 MKCircle类是在4.0中添加的。 我做了一些更多的测试,它似乎只会导致iPhone 3G上的严重问题。 3GS和模拟器工作正常。 我在乐器中没有看到任何尖刺,所以很难调查此问题。 – rule 2010-08-01 13:05:42