开发者

Memory Leaks when using NSPropertyListSerialization

开发者 https://www.devze.com 2023-01-15 02:16 出处:网络
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 开发者_

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号