1

我用导航控制器创建了一个非常简单的项目,它的根控制器是 viewController,只有一个按钮指向包含 mapView 的新 mapViewControler。

NavigatioController --> viewController - button --push--> mapViewController with mapView。

这是我的 mapViewController.h 代码:

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@interface mapViewController : UIViewController

@property (weak, nonatomic) IBOutlet MKMapView *mapView;

@end

这是我的 mapViewController.m 代码:

#import "mapViewController.h"    

@implementation mapViewController       
- (void)viewDidLoad
{
    [super viewDidLoad];        
}

-(void) viewWillDisappear:(BOOL)animated {

   //trigered when Back button pressed
   if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
        [self setMapView:nil];
        self.mapView.delegate = nil;
    }
    [super viewWillDisappear:animated];
}
@end

因此,当我单击按钮(segue - push)时,mapViewController 会显示并且 Live Bytes 增加 40MB - 我想是因为地图图像,但是当我单击返回按钮(navigationControl)时,内存仅减少 39 MB。所以 1MB 留在某处。如果我重复 100 次,则为 100MB。泄漏工具显示没有泄漏。

有人可以解释为什么每次单击“返回”时都会保留 1MB 以及如何摆脱它吗?

4

0 回答 0