0

我有一个方法并且不使用 ARC:

-(void)readAppPlist
{
    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: %@, formatL %d", errorDesc, format);
    }
    items = [[temp objectForKey:@"Items"] mutableCopy];
}

根据内存管理的规则,我需要在哪里释放变量 plistPath、plistXML、errorDesc、temp 的内存?我应该使用另一种方法,在此处释放它们还是将它们放入此类的 dealloc 全局方法中?

4

1 回答 1

7

假设您正确遵循了命名约定(这可能是一个很大的飞跃),答案将是:

plistPath:否
plistXML:否
errorDesc:否
temp:否

规则是如果你alloc copyretain它,你必须释放它(new算作alloc

于 2013-04-01T07:00:56.477 回答