I selected almost 1000 polygons on the map. I get the polygon path using
- (CGPathRef)polyPath:(MKPolygon *)polygon { MKMapPoint *points = [polygon points]; NSUInteger pointCount = [polygon pointCount]; NSUInteger i; if (pointCount < 3) return NULL; CGMutablePathRef path = CGPathCreateMutable(); if([polygon isKindOfClass:[MKPolygon class]]) { 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) { if([polygon isKindOfClass:[MKPolygon class]]) { 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); CGContextSetAlpha(context,1.0); CGContextStrokePath(context); } CGPathRelease(path); } } }
I get a leak in
CGPathRelease(interiorPath);
and
return path;
I know that I need to clear the path using CGPathRelease, but where to free it, while I have to go back.
Both leak huge memory. I have been working on this for several days, please help.
Thanks at Advance
source share