2
我想解析使用SBJSON的JSON订阅源,但每次我通过仪器运行它时,都会在一行中出现100%的内存泄漏。我肯定有不正确的东西,希望有所洞察。SBJSON解析器内存泄漏
我有一个城镇桌面,当你点击一个城镇时,这个饲料将运行并获取住在镇上的人的列表,并在桌面视图中解析它们。然而,每次我弹出的细节视图返回城镇的名单,并进入一个新的细节来看我结束了内存泄漏
SBJsonParser *parser = [[[SBJsonParser alloc] init] autorelease];
NSString *jsonString = [[NSString alloc] initWithData:[request responseData] encoding:NSUTF8StringEncoding];
id response = [parser objectWithString:jsonString error:NULL]; //100.0% memory leak
NSMutableDictionary *peopleDictionary = (NSMutableDictionary *)response;
NSMutableArray *buildingArray = [[NSMutableArray alloc] init];
if (peopleDictionary != nil) {
for (NSDictionary *dict in peopleDictionary) {
Person *incoming = [[Person alloc] init];
incoming.firstName = [dict objectForKey:@"firstName"];
incoming.lastName = [dict objectForKey:@"lastName"];
incoming.address = [dict objectForKey:@"address"];
[buildingFeedArray addObject:incoming];
[incoming release];
}
}
[jsonString release];
self.peopleArray = buildingFeedArray;
[self.tableView reloadData];
[buildingFeedArray release];
感谢您的回应,我从那之后转移到原生iOS 5 JSON解析器,它的工作原理好得多,但我尝试了您的解决方案,并删除了内存泄漏。 – Convolution
@卷动,很高兴听到。只是一个偶然的警告,只使用iOS5的API意味着你不能支持iOS 4.x,这意味着该应用程序不能安装在低于并包括iPhone 3G和iPod Touch第二代的模型 –
是的,是的,尽管开始在iOS 5中,我仍计划在未来的项目中包含此代码修复以支持较老的用户。 – Convolution