我正在构建的一个应用程序中遇到了一些严重的内存泄漏。我有一个位于 UITabBarview 内的 UINavigatonController。NavView 内部是一个 MKMap 视图。当您单击标注上的附件按钮时,将加载详细视图。在该详细视图中,我尝试使用 for(object in array) 循环从 plist 填充表。plist 是一个字典数组。我正在运行字典以找到一个带有作为标注标题的键的字典,然后从该字典中获取一个数组。在模拟器中一切正常,但我正在以我的方式进行大量内存泄漏。有什么想法吗?
- (void)viewDidLoad {
self.title = @"Route Details";
NSString *path = [[NSBundle mainBundle] pathForResource:@"stopLocation" ofType:@"plist"];
holderArray = [[NSMutableArray alloc] initWithContentsOfFile:path];
[self getRouteArray];
routeDetails.delegate = self;
routeDetails.dataSource = self;
}
-(void)getRouteArray{
for (NSMutableDictionary *dictionary in holderArray) {
//NSString *stopName = [dictionary objectForKey:@"StopName"];
//NSString *stopName = [[NSString alloc] initWithString:[dictionary objectForKey:@"StopName"]];
BOOL testString = [currentRoute isEqualToString:[dictionary objectForKey:@"StopName"]];
if (testString) {
routeArray = [[NSMutableArray alloc] initWithArray:[dictionary objectForKey:@"RouteService"]];
}
}
}
- (void)dealloc {
[routeArray release];
[routeDetails release];
[super dealloc];
}
holderArray 是一个 ivar,路由数组也是如此。如您所见,我尝试了几种分配 nstrings 和数组的方法,但似乎都产生了相同的泄漏。根据我从 NSCFString、NSCFDictionary 和 NSCFArry 泄漏的性能工具。我在 dealloc 中释放了 routeArray,它工作正常,但是如果我释放 holderArray,每当我从详细视图返回我的地图时,它就会崩溃。我想我真的不确定如何处理 for 循环中使用的字符串和字典。
只需添加详细视图,就可以像这样创建:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
NSString *selectedRouteName = [NSString stringWithFormat:@"%@",view.annotation.title];
RouteDetailView *rdc = [[RouteDetailView alloc] initWithNibName:@"RouteDetailView" bundle:nil];
[rdc setCurrentRoute:selectedRouteName];
[self.navigationController pushViewController:rdc animated:YES];
[rdc release];
}
抱歉,如果以上任何内容不清楚。让我知道,我可以尝试改写它。