我创建了一个谷歌map
视图,我在其中放置了一些注释并在加载时放置它们,但是当我连续更改我的相机视图时,内存消耗过高约200MB。 FPS率也从30降至5或6。我的应用程序只会崩溃。我怎么能释放那个记忆?这是我移动摄像机角度时我正在做的代码,
- (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
}
}
上面的代码标题标签是显示从当前位置到相机位置的距离的标签。 以下是内存消耗和FPS的图像。
答案 0 :(得分:0)
你可以尝试, 更改此委托方法:
- (void)mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position{
[self updateCenterOfScreenMarker:position.target];
}