J'ai rendu près de 1000 polygones dans la carte. Je reçois le chemin du polygone en utilisantFuite de mémoire énorme dans 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);
}
}
}
Je reçois fuite dans
CGPathRelease(interiorPath);
et
return path;
Je sais que je dois libérer chemin à l'aide CGPathRelease mais où pour le libérer tout je dois revenir.
Les deux fuites une énorme mémoire. J'ai travaillé dessus pendant des jours, aide svp.
Merci à l'avance
Merci pour votre réponse Nick..I a travaillé là-dessus .. Mais encore il fuit .. – iPrabu
Juste pour que vous Il est clair que vous devez ajouter le 'CGPathRelease()' après chaque point auquel vous appelez '-createPolyPath:', et pas seulement l'heure à laquelle vous l'appelez. –
Désolé l'homme ne pouvait pas le faire correctement. J'ai donné CGPathRelease() après le -createPolyPath: appelé. Toujours des fuites. – iPrabu