1

在我的 iPhone 应用程序中,我有一个地图视图。在此,我显示了许多 pin 视图取决于来自 Web 服务器的数据。这是我使用的方法。

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    NSString *identifier = @"myPin";
    self.pinView = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
    if (self.pinView == nil) {
        self.pinView= [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]autorelease];     //11.1%
    } else {
        self.pinView.annotation = annotation;
    }
    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];  //20.4%
    [rightButton setTitle:annotation.title forState:UIControlStateNormal];
    self.pinView.rightCalloutAccessoryView = rightButton;   //2.7%

    MyAnnotation *annot = (MyAnnotation*)annotation;

    UIImageView *egoimageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"defaultPerson"]];    //17.5%
    NSString *imageUrl = [NSString stringWithFormat:@"%@%@", CommonImageURL, [friendsProfileImageArray objectAtIndex:annot.tag]];     //9.4%

    if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] &&
        ([UIScreen mainScreen].scale == 2.0)) {
        // Retina display
        [egoimageView setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"defaultPerson@2x.png"]];    //2.6%

        egoimageView.image = [UIImage imageWithCGImage:egoimageView.image.CGImage scale:egoimageView.image.size.width/25 orientation:egoimageView.image.imageOrientation];
    } else {
        // non-Retina display
        [egoimageView setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"defaultPerson.png"]];    //14.6%

        egoimageView.image = [UIImage imageWithCGImage:egoimageView.image.CGImage scale:egoimageView.image.size.width/25 orientation:egoimageView.image.imageOrientation];   //1.6%
    }

    [egoimageView sizeToFit];
    self.pinView.leftCalloutAccessoryView = egoimageView;    //3.1%
    [egoimageView release];
    self.pinView.canShowCallout=YES;
    self.pinView.animatesDrop=YES;

    //pin color based on status.....
    if ([annot.relationshipStatus intValue]==2 )
        self.pinView.pinColor=MKPinAnnotationColorGreen;
    else
        self.pinView.pinColor=MKPinAnnotationColorPurple;    //17.1%

    return self.pinView;
}

在这我已经提到了内存分配的百分比。如果我不断加载地图,总内存使用量会增加,应用程序会崩溃。我该如何正确解决这个问题?我试图修复它,但我不知道我还能做些什么。

请帮助,提前谢谢。

4

0 回答 0