【发布时间】:2012-03-06 09:43:16
【问题描述】:
我有很多这样的注释(大约 2400 个),但这是我的问题。
我收到以下错误
在第 81 行分配并存储到的对象的潜在泄漏 'annot1' 在第 81 行分配并存储到“annot2”中的对象的潜在泄漏
在第 81 行分配并存储到的对象的潜在泄漏 'annot3'
等等。这是我的代码:
MKPointAnnotation *annot1 = [[MKPointAnnotation alloc] init];
annot1.title = @"A";
annot1.subtitle=@"A1";
annot1.coordinate = CLLocationCoordinate2DMake(21.978954, 120.752663);
[mapView addAnnotation:annot1];
MKPointAnnotation *annot2 = [[MKPointAnnotation alloc] init];
annot2.title = @"B";
annot2.subtitle=@"B2";
annot2.coordinate = CLLocationCoordinate2DMake(21.988607, 120.748703);
[mapView addAnnotation:annot2];
MKPointAnnotation *annot4 = [[MKPointAnnotation alloc] init];
annot4.title = @"C";
annot4.subtitle=@"C1";
annot4.coordinate = CLLocationCoordinate2DMake(22.008867, 120.743637);
[mapView addAnnotation:annot4];
MKPointAnnotation ***strong text**annot5 = [[MKPointAnnotation alloc] init];
annot5.title = @"D";
annot5.subtitle=@"D1";
annot5.coordinate = CLLocationCoordinate2DMake(22.016190, 120.837601);
[mapView addAnnotation:annot5];
MKPointAnnotation *annot6 = [[MKPointAnnotation alloc] init];
annot6.title = @"E";
annot6.subtitle=@"E1";
annot6.coordinate = CLLocationCoordinate2DMake(22.024183, 120.743401);
[mapView addAnnotation:annot6];
MKPointAnnotation *annot7 = [[MKPointAnnotation alloc] init];
annot7.title = @"F";
annot7.subtitle=@"F1";
annot7.coordinate = CLLocationCoordinate2DMake(22.055653, 121.509689);
[mapView addAnnotation:annot7];
MKPointAnnotation *annot8 = [[MKPointAnnotation alloc] init];
annot8.title = @"G";
annot8.subtitle=@"G2";
annot8.coordinate = CLLocationCoordinate2DMake(22.070082, 120.713684);
[mapView addAnnotation:annot8];
等
{
【问题讨论】:
-
您在使用 ARC 吗?如果您不使用 ARC,则需要在将对象添加到 mapView 后释放它们。
-
尝试 ARC 后,同样的事情仍然发生。我在哪里释放它?我在 ViewDidLoad 中有注释。如果您需要更多信息,请告诉我。 @弗雷迪
-
你读过memory management rules吗?此外,该代码非常重复,您可能需要考虑将数据与创建注释的代码分开。
-
感谢 Georg,我会继续阅读的。
标签: ios cocoa-touch memory-leaks mapkit