【发布时间】:2010-02-04 22:34:36
【问题描述】:
要在 mapView 上更新 GPS 指示器的位置...
[mapView removeAnnotation:myGpsAnnotation];
[myGpsAnnotation release];
myGpsAnnotation = nil;
myGpsAnnotation = [[MapLocationAnnotation alloc] initWithCoordinate:region.center annotationType:MapAnnotationTypeGps title:MAP_ANNOTATION_TYPE_GPS];
[mapView addAnnotation:myGpsAnnotation];
...我看到 Instruments(模拟器)中的净内存在缓慢攀升。没有“泄漏”信号,但“Net Bytes”和“#Net”缓慢增加......除非这段代码被注释掉。所以我 100% 确定这是有问题的代码。
但是如果我执行以下操作...
[mapView removeAnnotation:myGpsAnnotation];
[myGpsAnnotation release];
myGpsAnnotation = nil;
myGpsAnnotation = [[MapLocationAnnotation alloc] initWithCoordinate:region.center annotationType:MapAnnotationTypeGps title:MAP_ANNOTATION_TYPE_GPS];
[mapView addAnnotation:myGpsAnnotation];
[mapView removeAnnotation:myGpsAnnotation];
[mapView addAnnotation:myGpsAnnotation];
[mapView removeAnnotation:myGpsAnnotation];
[mapView addAnnotation:myGpsAnnotation];
...然后“Net Bytes”和“#Net”增加得更快。这可能不是我的错误,我正在尝试追踪 MapKit 中的泄漏吗?我真的在泄漏内存吗?同样,“泄漏”下什么也没有出现,但我不明白为什么净值会不断攀升。
感谢您的帮助,-戈德
【问题讨论】:
-
我对你如何做到这一点很感兴趣,如果你有一个和平的代码,你可以粘贴它,就像我们可以学习一样,THX 对我们有很多帮助......跨度>
标签: iphone memory-leaks annotations mapkit android-mapview