在NSMutableArray中存储CLLocationCoordinates2D [英] Storing CLLocationCoordinates2D in NSMutableArray

查看:53
本文介绍了在NSMutableArray中存储CLLocationCoordinates2D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过一番搜索,我得到了以下解决方案:
引用

After some searching, I got the following solution : reference.

CLLocationCoordinate2D* new_coordinate = malloc(sizeof(CLLocationCoordinate2D));
new_coordinate->latitude = latitude;
new_coordinate->longitude = longitude;
[points addObject:[NSData dataWithBytes:(void *)new_coordinate
length:sizeof(CLLocationCoordinate2D)]];
free(new_coordinate);

并以以下方式访问它:

CLLocationCoordinate2D* c = (CLLocationCoordinate2D*) [[points objectAtIndex:0] bytes];

但是,有人声称这里存在内存泄漏吗?谁能建议我泄漏在哪里以及如何修复。此外,还有更好的方法在NSMutableArray中存储CLLocationCoordinate2D列表吗?由于我是Objective C新手,请提供示例代码。

However, someone claims that there is a memory leak here? Can anyone suggest me where is the leak and how to fix it. Further, is there a better way of storing a list of CLLocationCoordinate2D in NSMutableArray? Please give sample code since I am an Objective C newbie.

推荐答案

没有泄漏,只是浪费堆内存。

There's no leak, just a waste of heap memory.

您可以使用

CLLocationCoordinate2D new_coordinate;
new_coordinate.latitude = latitude;
new_coordinate.longitude = longitude;
[points addObject:[NSData dataWithBytes:&new_coordinate length:sizeof(new_coordinate)]];

这篇关于在NSMutableArray中存储CLLocationCoordinates2D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆