Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 内存警告映射覆盖_Ios_Ios6_Mkmapview - Fatal编程技术网

Ios 内存警告映射覆盖

Ios 内存警告映射覆盖,ios,ios6,mkmapview,Ios,Ios6,Mkmapview,我对ios的内存使用有疑问。我已经实现了如下所示的代码,并在设备上运行了大约10分钟,它停止了,并向我发出警告“已收到内存警告”。我想知道为什么我会收到这个警告 NSArray *ants = [mapView overlays]; for(bb = 0; bb < [polygonArray count]; bb++){ int attr=[[idArray objectAtIndex:bb]floatValue]; coords = malloc(s

我对ios的内存使用有疑问。我已经实现了如下所示的代码,并在设备上运行了大约10分钟,它停止了,并向我发出警告“已收到内存警告”。我想知道为什么我会收到这个警告

NSArray *ants = [mapView overlays];
for(bb = 0; bb < [polygonArray count]; bb++){
        int attr=[[idArray objectAtIndex:bb]floatValue];


        coords = malloc(sizeof(CLLocationCoordinate2D) * [[polygonArray objectAtIndex:bb] count]);
        for (int a = 0;a < [[polygonArray objectAtIndex:bb] count]; a++){
            coords[a].latitude = [[[[polygonArray objectAtIndex:bb]objectAtIndex:a]objectAtIndex:0]doubleValue];
            coords[a].longitude = [[[[polygonArray objectAtIndex:bb]objectAtIndex:a]objectAtIndex:1]doubleValue];
        }
        polygon = [[MKPolygon alloc]init];
        polygon = [MKPolygon polygonWithCoordinates:coords count:[[polygonArray objectAtIndex:bb]count]]; 
        //free(coords);
        [previousPolygons addObject:polygon];

            }
        [mapView addOverlay:polygon];
        }

    }
[mapView removeOverlays:ants];
NSArray*ants=[mapView叠加];
对于(bb=0;bb<[多边形阵列计数];bb++){
int attr=[[idArray objectAtIndex:bb]floatValue];
coords=malloc(sizeof(CLLocationCoordinate2D)*[[polygerray objectAtIndex:bb]计数];
对于(int a=0;a<[[polygerray objectAtIndex:bb]计数];a++){
坐标[a]。纬度=[[[[PolyGray objectAtIndex:bb]objectAtIndex:a]objectAtIndex:0]doubleValue];
坐标[a]。经度=[[[Polygerray对象索引:bb]对象索引:a]对象索引:1]双值];
}
多边形=[[MKPolygon alloc]init];
多边形=[MKPolygon polygon with coordinates:coords count:[polygorray objectAtIndex:bb]count];
//免费(coords);
[以前的多边形添加对象:多边形];
}
[地图视图添加覆盖:多边形];
}
}
[地图视图移除覆盖:蚂蚁];

您似乎有更多的结束括号,而不是开始括号,因此可能比您向我们展示的更多,但我在下面展示了我认为可以改进代码的内容

NSArray *ants = [mapView overlays];
for(bb = 0; bb < [polygonArray count]; bb++){
    int attr=[[idArray objectAtIndex:bb]floatValue];


    coords = malloc(sizeof(CLLocationCoordinate2D) * [[polygonArray objectAtIndex:bb] count]);
    for (int a = 0;a < [[polygonArray objectAtIndex:bb] count]; a++){
        coords[a].latitude = [[[[polygonArray objectAtIndex:bb]objectAtIndex:a]objectAtIndex:0]doubleValue];
        coords[a].longitude = [[[[polygonArray objectAtIndex:bb]objectAtIndex:a]objectAtIndex:1]doubleValue];
    }
    //Remove the next line because polygonWIthCoordinates creates one for you
    //polygon = [[MKPolygon alloc]init];
    polygon = [MKPolygon polygonWithCoordinates:coords count:[[polygonArray objectAtIndex:bb]count]]; 
    //reinstate this line
    free(coords);
    [previousPolygons addObject:polygon];

}
//This is outside the for-loop so you'll only be adding the last polygon
[mapView addOverlay:polygon];
}

}
[mapView removeOverlays:ants];
NSArray*ants=[mapView叠加];
对于(bb=0;bb<[多边形阵列计数];bb++){
int attr=[[idArray objectAtIndex:bb]floatValue];
coords=malloc(sizeof(CLLocationCoordinate2D)*[[polygerray objectAtIndex:bb]计数];
对于(int a=0;a<[[polygerray objectAtIndex:bb]计数];a++){
坐标[a]。纬度=[[[[PolyGray objectAtIndex:bb]objectAtIndex:a]objectAtIndex:0]doubleValue];
坐标[a]。经度=[[[Polygerray对象索引:bb]对象索引:a]对象索引:1]双值];
}
//删除下一行,因为polygonWIthCoordinates会为您创建一行
//多边形=[[MKPolygon alloc]init];
多边形=[MKPolygon polygon with coordinates:coords count:[polygorray objectAtIndex:bb]count];
//恢复这条线
免费(coords);
[以前的多边形添加对象:多边形];
}
//这在for循环之外,因此您将只添加最后一个多边形
[地图视图添加覆盖:多边形];
}
}
[地图视图移除覆盖:蚂蚁];

作为一般提示,如果您将
[polygerray objectAtIndex:bb]
分配给一个命名良好的变量,并使用
bb
a
等更具描述性的变量,那么您的代码将更具可读性,但我想您可能只是为了让公众看不到您的代码而更改了它们。