我在地圖中渲染了近1000個多邊形。我得到使用巨大的CGMutablePathRef中的內存泄漏
- (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);
}
}
}
我得到泄漏多邊形的路徑
CGPathRelease(interiorPath);
和
return path;
我知道,我一直在使用CGPathRelease釋放路徑,但在那裏將其釋放,而我必須回來。
兩者都泄漏了巨大的記憶。 我一直在爲此工作數日,請幫忙。
由於提前
謝謝您的回答Nick..I上它的工作。但它仍然泄漏.. – iPrabu 2010-11-13 12:35:28
只要你清楚地說,你必須在你調用'-createPolyPath:'的每一個點之後添加'CGPathRelease()',而不僅僅是你自己調用它的時間。 – 2010-11-13 13:01:32
對不起,人不能正確。我在-createPolyPath:called後給了CGPathRelease()。仍然泄漏。 – iPrabu 2010-11-13 13:32:31