我在使用 iPhone GPS 'runkeeper' 类型的应用程序时遇到了一点问题。该应用程序几乎在所有方面都可以正常工作,我设计它的方式是将 CLLocation 对象添加到数组中,然后将该对象数组存储在 MySQL 数据库中。然后,当我打开一个地图视图时,我只需从服务器中拉出数组,并通过一些操作,使用数据将图钉添加到地图中。
就像我说的那样,这一切都运行良好,坐在我的办公桌前时,在模拟器和设备上运行良好(顺便说一句,使用仪器 - 没有泄漏)。但是,当我在设备上测试了应用程序并实际离开房子并在街上走了 15 分钟时,应用程序在 CLLocationManager 对象停止更新并且数组已发布到 MySQL 时崩溃 - 几乎可以肯定(我认为)因为内存问题。
既然如此,鉴于我是一个相对的菜鸟,所以要温柔,我正在寻找有关开发一种更有效的方法将对象存储到数组中的建议,以便可能大量存储的位置数据不会' t 融化应用程序。
这是我正在使用的代码的(选择):
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
//注意我已经取出了确定CLocation对象是否有效的代码,还有一两个其他的小东西
if (recording == YES) {//the start button has been pressed but the stop button hasn't.
if (alreadyBeenRound == NO) {
if (firstRecord == YES) {
//create the pointsonRoute array
if (pointsOnRouteExists == NO) {
pointsOnRoute = [[NSMutableArray alloc] init];
pointsOnRouteExists = YES;
}
[pointsOnRoute removeAllObjects];
firstRecord = NO; //after setting first record, can move on
}
[pointsOnRoute addObject:newLocation];
//more stuff taken out here
alreadyBeenRound = YES;
} else {
[pointsOnRoute addObject:newLocation];
}
//I do release the array