Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 962783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:33:51+00:00 2026-05-16T01:33:51+00:00

I’m working on an iPhone app that shows a map with multiple circle overlays

  • 0

I’m working on an iPhone app that shows a map with multiple circle overlays on certain locations.
I’m running into serious memory issues and crashes when I add more than 6 circles and I zoom out far enough that they are all visible.
When I zoom in such that only 2 circles are visible, all is fine. When I remove the MKOverlays, everything works fine.

Anyone who recognizes this behavior?

Code that creates the overlays. I store the overlays in a NSMutableDictionary for future reference (to be able to remove them from the map and to prevent double overlays)

- (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];
        }
    }
}

Code that makes the overlay views

#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;
}

Code that releases the overlay cache

- (void)dealloc {
    [overlayCache release];
    [mapView release];
    [super dealloc];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:33:52+00:00Added an answer on May 16, 2026 at 1:33 am

    I am seeing the same thing happen. I am drawing MKPolylines instead of circles, but I have exactly the same problem. 1 line works fine, but when I start to add several and try moving the map around it crashes with memory warnings. I’d paste my code, but it is pretty much identical to the above changing circle for line.

    EDIT: the problem seems to be that each overlay creates a new core animation layer. there is a workaround here – https://devforums.apple.com/thread/48154?tstart=0 Also, I believe this is a known bug that should be fixed in the next release

    EDIT:the workaround – “It isn’t a problem with the API but rather the implementation. My suggestion to manually consolidate them into one is a workaround for the moment.

    For example, here’s how you could implement a MultiPolygon and corresponding view:”

        @interface MultiPolygon : NSObject <MKOverlay> {
        NSArray *_polygons;
        MKMapRect _boundingMapRect;
    }
    
    - (id)initWithPolygons:(NSArray *)polygons;
    @property (nonatomic, readonly) NSArray *polygons;
    
    @end
    
    @implementation MultiPolygon
    
    @synthesize polygons = _polygons;
    
    - (id)initWithPolygons:(NSArray *)polygons
    {
        if (self = [super init]) {
            _polygons = [polygons copy];
    
            NSUInteger polyCount = [_polygons count];
            if (polyCount) {
                _boundingMapRect = [[_polygons objectAtIndex:0] boundingMapRect];
                NSUInteger i;
                for (i = 1; i < polyCount; i++) {
                    _boundingMapRect = MKMapRectUnion(_boundingMapRect, [[_polygons objectAtIndex:i] boundingMapRect]);
                }
            }
        }
        return self;
    }
    
    - (void)dealloc
    {
        [_polygons release];
        [super dealloc];
    }
    
    - (MKMapRect)boundingMapRect
    {
        return _boundingMapRect;
    }
    
    - (CLLocationCoordinate2D)coordinate
    {
        return MKCoordinateForMapPoint(MKMapPointMake(MKMapRectGetMidX(_boundingMapRect), MKMapRectGetMidY(_boundingMapRect)));
    }
    
    @end
    
    
    
    @implementation MultiPolygonView
    
    - (CGPathRef)polyPath:(MKPolygon *)polygon
    {
        MKMapPoint *points = [polygon points];
        NSUInteger pointCount = [polygon pointCount];
        NSUInteger i;
    
        if (pointCount < 3)
            return NULL;
    
        CGMutablePathRef path = CGPathCreateMutable();
    
        for (MKPolygon *interiorPolygon in polygon.interiorPolygons) {
            CGPathRef interiorPath = [self polyPath:interiorPolygon];
            CGPathAddPath(path, NULL, interiorPath);
            CGPathRelease(interiorPath);
        }
    
        CGPoint relativePoint = [self pointForMapPoint:points[0]];
        CGPathMoveToPoint(path, NULL, relativePoint.x, relativePoint.y);
        for (i = 1; i < pointCount; i++) {
            relativePoint = [self pointForMapPoint:points[i]];
            CGPathAddLineToPoint(path, NULL, relativePoint.x, relativePoint.y);
        }
    
        return path;
    }
    
    - (void)drawMapRect:(MKMapRect)mapRect
              zoomScale:(MKZoomScale)zoomScale
              inContext:(CGContextRef)context
    {
        MultiPolygon *multiPolygon = (MultiPolygon *)self.overlay;
        for (MKPolygon *polygon in multiPolygon.polygons) {
            CGPathRef path = [self polyPath:polygon];
            if (path) {
                [self applyFillPropertiesToContext:context atZoomScale:zoomScale];
                CGContextBeginPath(context);
                CGContextAddPath(context, path);
                CGContextDrawPath(context, kCGPathEOFill);
                [self applyStrokePropertiesToContext:context atZoomScale:zoomScale];
                CGContextBeginPath(context);
                CGContextAddPath(context, path);
                CGContextStrokePath(context);
                CGPathRelease(path);
            }
        }
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.