2011-01-24 42 views
1
NSUInteger numPoints = [[self locationFake] count]; 
CLLocationCoordinate2D *pointsPtr = malloc(numPoints * sizeof(CLLocationCoordinate2D)); 

for(int counter=0; counter<numPoints; counter++) { 
    pointsPtr[counter] = [[[self locationFake] objectAtIndex:counter] coordinate]; 
} 

// (1) 
MKPolyline *polyline = [MKPolyline polylineWithCoordinates:pointsPtr count:numPoints]; 

...MKPolyline和內存?

free(pointsPtr); 
pointsPtr = NULL; 

我已經創建了MKPolyline對象(1)之後,我可以釋放這些點所使用的內存,或者做了MKPolyline保持引用它的創作之後的內存和我不應該免費的點,直到我完全完成對MKPolyline對象?

回答

4

據我所知,你可以釋放內存。我使用一個堆棧分配的固定大小的緩衝區,它工作正常,這意味着多段線必須在某處複製這些座標。

+0

您好,我已經使用MKMapPoint * pointArr = malloc(sizeof ..),free(pointArr)。雖然我仍然面臨記憶問題。任何其他指導? – Paradise 2015-08-04 12:56:36