我一直在使用工具来查找未正确释放的分配。我有 MKMapViewDelegate 在实例化后通过实例方法添加地图。我可以在调用树中看到,在 ViewDelegate 释放后,此方法一直保留大约 300KB 的内存。我注释掉了代码的主要部分,它仍然只用这一行来维护内存:
self.map = [[MKMapView alloc] initWithFrame:CGRectMake(10, 210, 300, 125)];
我查看对象列表,MKMapView 本身并不存在,但是当我不断创建新的 ViewDelegates 时,内存不断增加。以下是地图的定义方式:
@property (strong, nonatomic) MKMapView *map;
地图的委托设置为 nil,以及 ViewDelegate 的 dealloc 上的引用
self.map.delegate = nil;
self.map = nil;