我有没有ARC的方法来读取plist文件内容:
-(void)readAppFile
{
NSString *plistPath = [self getDataFileDestinationPath];
NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
NSString *errorDesc = nil;
NSPropertyListFormat format;
NSMutableDictionary *temp = (NSMutableDictionary *) [NSPropertyListSerialization propertyListFromData:plistXML mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&errorDesc];
if (!temp) {
NSLog(@"Error reading plist: %@, format: %d", errorDesc, format);
}
items = [[temp objectForKey:@"Items"] mutableCopy];
NSLog(@"Read file!");
}
我的内存泄漏很严重!所以我用这一行items = [[[temp objectForKey:@"Items"] mutableCopy] autorelease];
替换代码的结尾,但现在我有Thread 1: EXC_BAD_ACCESS (code=1, addres=0x6000000008)
。今天是第二天我不知道如何处理这种方法。
答案 0 :(得分:0)
尝试在重新分配之前明确发布items
:
if (items != nil) [items release];
items = [[temp objectForKey:@"Items"] mutableCopy];