Memory Leaks when using NSPropertyListSerialization
This method in my class reads a previously created plist, but when it does NSPropertyListSerialization leaks all over the place. NSDates and NSCFStrings, mostly. Any suggestions on what I can do 开发者_Python百科to prevent this?
- (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;
}
You might try the propertyListWithData:options:format:error:
method instead.
精彩评论