我正在研究一個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