使用NSPropertyListSerialization时内存泄漏

时间:2010-09-02 16:29:34

标签: iphone objective-c cocoa

我班级中的这个方法读取以前创建的plist,但是当它确实存在时,NSPropertyListSerialization会在整个地方泄漏。 NSDates和NSCFStrings,主要是。关于我可以做些什么来防止这种情况的任何建议?

- (id)readPlist:(NSString *)fileName {  

    NSData *plistData;  
    NSString *errorA;  
    NSPropertyListFormat format;  
    id plist;  

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *localizedPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:fileName];  
    plistData = [NSData dataWithContentsOfFile:localizedPath];   

    plist = [NSPropertyListSerialization propertyListFromData:plistData mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&errorA];  
    if (!plist) {  
        DLog(@"Error reading plist from file '%s', error = '%s'", [localizedPath UTF8String], [errorA UTF8String]);  
        [errorA release];  
    }

    return plist;  
} 

1 个答案:

答案 0 :(得分:0)