autorelease导致系统崩溃iOS

时间:2013-04-09 18:32:37

标签: ios objective-c memory-management autorelease

我有没有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)。今天是第二天我不知道如何处理这种方法。

1 个答案:

答案 0 :(得分:0)

尝试在重新分配之前明确发布items

if (items != nil) [items release];
items = [[temp objectForKey:@"Items"] mutableCopy];