我创建了一个简单的 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 不允许我发布它。如果有兴趣,我可以通过电子邮件发送给某人。
我做错了什么或错过了什么?