I have many of this annotations(about 2400), but here is my problem.
I get the following errors
potential leak of an object allocated on line 81 and stored into
‘annot1’
potential leak of an object allocated on line 81 and stored into ‘annot2’potential leak of an object allocated on line 81 and stored into
‘annot3’
And so on. Here is my code:
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];
etc
{
If you’re not using ARC then you should release the object after you add it to your mapview.
For example:
Should be updated to:
The reason is that your object reference count never hit zero and the object is never released.
When you allocate an object it has a reference count of 1. If you add an object to an array or dictionary the reference count is incremented. So after the following block of code you have a reference count of two.
Now, if you call release on annot1 after you add it to your mapview the object isn’t really released yet. This is because the data structure in your mapview is holding reference to it.
Once you’re done with your mapview and it is released then annot1 is finally destroyed.