【发布时间】:2014-01-20 11:32:36
【问题描述】:
加载谷歌地图时在分析器中出现泄漏。我根据谷歌的示例代码创建了一个非常简单的视图控制器,我发现地图加载时出现泄漏。我相信泄漏是在 SDK 本身。有没有人遇到过这个问题并找到了解决方案?
基本视图控制器
//
// JRCViewController.m
// GoogleMapsInterface
//
// Created by Jake Cunningham on 15/01/2014.
// Copyright (c) 2014 Jake Cunningham. All rights reserved.
//
#import "JRCViewController.h"
@interface JRCViewController (){
BOOL firstLocationUpdate_;
GMSMapView *mapView;
}
@end
@implementation JRCViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
longitude:151.2086
zoom:6];
mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
[mapView addObserver:self
forKeyPath:@"myLocation"
options:NSKeyValueObservingOptionNew
context:NULL];
self.view = mapView;
dispatch_async(dispatch_get_main_queue(), ^{
mapView.myLocationEnabled = YES;
});
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
if (!firstLocationUpdate_) {
// If the first location update has not yet been recieved, then jump to that
// location.
firstLocationUpdate_ = YES;
CLLocation *location = [change objectForKey:NSKeyValueChangeNewKey];
mapView.camera = [GMSCameraPosition cameraWithTarget:location.coordinate
zoom:14];
}
}
@end
【问题讨论】:
-
我在我的应用程序中编写了相同的代码,每次我按下开关时,我的应用程序都会增加 50 MB。这是非常糟糕的:(你找到答案了吗?
-
不,恐怕不行,我最后还是用了苹果地图。如果我遇到答案,我会告诉你。
标签: ios google-maps memory-leaks