1

I have created a google map view where I placed some annotations and placing them at the time of loading, but when I change my camera view continuously, memory consumption gets too high about 200MB. FPS rate also lowers down from 30 to 5or6. My app goes nothing but crashing. How can I release that memory ? Here is my code of what I am doing when I move camera angle,

- (void)mapView:(GMSMapView *)mapview didChangeCameraPosition:(GMSCameraPosition *)position 
{
    [self updateCenterOfScreenMarker:position.target];
}

- (void)updateCenterOfScreenMarker:(CLLocationCoordinate2D)coordinate {
       [self updateMarkers:currentLocation];
    CLLocation * centerOfGreen = [self getLocationCenterOfGreen];
    if (centerOfGreen) {
        CLLocation * currentCamera = [[CLLocation alloc] initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
        CLLocationDistance distance = [currentCamera distanceFromLocation:centerOfGreen];
        distanceFromCameraToGolfer = [currentCamera distanceFromLocation:currentLocation];
        [currentCamera release];

        distanceFromCameraToCenterOfGreen = distance;
        if (isYards) {
            distanceFromCameraToCenterOfGreen *= METERS_TO_YARDS;
            distanceFromCameraToGolfer *= METERS_TO_YARDS;
        }

        if (centerMarker) {
            centerMarker.map = nil; // You can remove a marker from the map by setting your GMSMarker's map property to nil.
            [centerMarker release];
            centerMarker = nil;
            headingLabel.text=@"";
            headingLabel=nil;
            headingLabel.text=nil;
            headingLabel2.text=@"";
            headingLabel2=nil;
            headingLabel2.text=nil;
            headingLabel3.text=@"";
            headingLabel3=nil;
            headingLabel3.text=nil;
            headingLabel4.text=@"";
            headingLabel4=nil;
            headingLabel4.text=nil;
            centerMarker.icon =nil;
        }


        if (mapView) {
//            centerMarker = [GMSMarker markerWithPosition:coordinate];
            headingLabel.text=@"";
            headingLabel2.text=@"";
            headingLabel3.text=@"";
            headingLabel4.text=@"";

            if(distanceFromCameraToGolfer >= 1000)
            {
                headingLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 180, 120, 30)];
                headingLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(160, 180, 40, 30)];
                headingLabel3 = [[UILabel alloc] initWithFrame:CGRectMake(200, 180, 20, 30)];
                headingLabel4 = [[UILabel alloc] initWithFrame:CGRectMake(225, 180, 70, 30)];
            }
            else
            {
                headingLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 180, 100, 30)];
                headingLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(125, 180, 40, 30)];
                headingLabel3 = [[UILabel alloc] initWithFrame:CGRectMake(170, 180, 20, 30)];
                headingLabel4 = [[UILabel alloc] initWithFrame:CGRectMake(195, 180, 70, 30)];
            }
            headingLabel.font=[UIFont fontWithName:@"Roboto-Bold" size:30];
            headingLabel2.font=[UIFont fontWithName:@"Roboto-Regular" size:30];
            headingLabel3.font=[UIFont fontWithName:@"Roboto-Light" size:30];
            headingLabel4.font=[UIFont fontWithName:@"Roboto-Bold" size:30];

            headingLabel.textColor=[UIColor whiteColor];
            headingLabel2.textColor=[UIColor whiteColor];
            headingLabel3.textColor=[UIColor yellowColor];
            headingLabel4.textColor=[UIColor whiteColor];

            headingLabel.textAlignment=NSTextAlignmentRight;
            headingLabel2.textAlignment=NSTextAlignmentCenter;
            headingLabel3.textAlignment=NSTextAlignmentCenter;
            headingLabel4.textAlignment=NSTextAlignmentLeft;


            headingLabel.text=nil;
            headingLabel2.text=nil;
            headingLabel3.text=nil;
            headingLabel4.text=nil;

//            centerMarker.title = nil;
//            centerMarker.snippet = nil;
//            centerMarker.groundAnchor = CGPointMake(0.5, 0.5);
            str=@"";
            str = [NSString stringWithFormat:@"%d",distanceFromCameraToGolfer];
            str2=@"";

            NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
            NSString * units = [defaults objectForKey:PREFERENCE_KEY_UNITS];
            if ([units isEqualToString:@"yards"]) {
                str2 = [NSString stringWithFormat:@"Yd"]; 
            }
            else
            {
                str2 = [NSString stringWithFormat:@" m"];
            }

            str3=@"";
            str3 = [NSString stringWithFormat:@"/"];
            str4=@"";
            str4 = [NSString stringWithFormat:@"%d", distanceFromCameraToCenterOfGreen];

            if([str4 intValue]>=0 && [str4 intValue]<=14)
            {
                headingLabel.hidden=YES;
                headingLabel2.hidden=YES;
                headingLabel3.hidden=YES;
                headingLabel4.hidden=YES;
            }

            headingLabel.text=str;
            headingLabel2.text=str2;
            headingLabel3.text=str3;
            headingLabel4.text=str4;
            [mapView addSubview:headingLabel];
            [mapView addSubview:headingLabel2];
            [mapView addSubview:headingLabel3];
            [mapView addSubview:headingLabel4];
//            centerMarker.icon = [self addText:[UIImage imageNamed:@"grid.png"] text:@""  red:255 green:255 blue:255];
//            centerMarker.map = mapView;
//            centerMarker.tappable=NO;
            [centerMarker retain];
            [headingLabel release];
            [headingLabel2 release];
            [headingLabel3 release];
            [headingLabel4 release];

        } // mapView

    }

}

Here in above code heading labels are the labels that show distance from current location to camera position. Following is the image of memory consumption and FPS.

Memory Consumption and FPS screenshot

4

1 回答 1

0

您可以尝试更改此委托方法:

- (void)mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position{
    [self updateCenterOfScreenMarker:position.target];
}
于 2015-02-23T11:40:15.300 回答