iPr*_*abu 4 iphone core-foundation cgpath
我在地图中渲染了近1000个多边形.我使用了多边形的路径
- (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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我弄漏了
CGPathRelease(interiorPath);
Run Code Online (Sandbox Code Playgroud)
和
return path;
Run Code Online (Sandbox Code Playgroud)
我知道我必须使用CGPathRelease释放路径,但在必须返回时将其释放.
两者都泄漏了巨大的记忆.我已经做了好几天了,请帮忙.
提前致谢
您应该重命名您的方法,-createPolyPath:以明确它返回需要释放的Core Foundation对象,然后在您调用的代码中-createPolyPath:,您需要像这样释放它:
CGPathRef path = [someObjectOrClass createPolyPath:somePolygon];
// Do some stuff with the path
CGPathRelease(path);
Run Code Online (Sandbox Code Playgroud)
请参阅"Core Foundation的内存管理编程指南":
| 归档时间: |
|
| 查看次数: |
4228 次 |
| 最近记录: |