【发布时间】:2013-03-15 23:45:00
【问题描述】:
我创建了一个简单的 UIViewController 来创建和销毁 GMSMapView。
- (void)viewDidAppear:(BOOL)animated
{
if ( !m_disappearing_bc_segue )
{
[super viewDidAppear:animated] ;
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude: self.location.latitude
longitude: self.location.longitude
zoom:9 ] ;
m_mapView = [GMSMapView mapWithFrame:CGRectMake(0, 0, 320, 420) camera:camera];
m_mapView.myLocationEnabled = NO ;
[m_mapView setMapType: kGMSTypeTerrain] ;
m_mapView.delegate = self ;
[self.view addSubview:m_mapView] ;
[self.view sendSubviewToBack:m_mapView] ;
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated] ;
[m_mapView clear] ;
[m_mapView stopRendering] ;
[m_mapView removeFromSuperview] ;
m_mapView = nil ;
}
我已将 Instruments 与 Allocations 工具一起使用。测试很容易。在 UINavigation ViewController 中,推送视图,回击并重复。每次推送和弹出包含上述 GMSMapView 的视图时,大约有 40kb 泄漏。我有一张来自 Instruments 的截图来说明这一点,但 stackoverflow 不允许我发布它。如果有兴趣,我可以通过电子邮件发送给某人。
我是做错了什么还是错过了什么?
【问题讨论】:
-
为什么每次都需要重新创建
GMSMapView? -
任何机会添加 m_mapView.delegate = nil;之前说 m_mapView=nil 会解决吗?它可能...
-
@SergeyKuryanov 基本上是为了释放内存。每个 GMSMapView 都会消耗一些严重的内存。我有一个迷你视图(屏幕的一半)和一个按钮驱动您查看最大化的版本。当我从最大化版本返回时,我想把它扔掉。
-
抱歉跑题了,但我尝试将自己的项目迁移到 GMaps,但我对此并不满意。如果它有内存泄漏,我只能建议你不要用地图显示另一个视图,而是增加当前的大小。
-
@SergeyKuryanov 我已经提交了一个错误 [link][code.google.com/p/gmaps-api-issues/issues/detail?id=5188] 没有其他事情可做。