0

我有没有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). 今天是第二天我不知道用这个方法做什么。

4

1 回答 1

0

items在重新分配之前尝试显式释放:

if (items != nil) [items release];
items = [[temp objectForKey:@"Items"] mutableCopy];
于 2013-04-09T20:08:11.637 回答