NSPropertyListSerialization Alternative?
Is there any code that I can use in place of this code snippet?
NSString *anError = nil;
id plist;
plist = [NSPropertyListSerialization propertyListFromData:rawCourseArray mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&anError];
if (anError != nil){
[anError release];
}
The code above causes a memory leak which I can't correct. I try releasing the error but no luck. Is there another way to serialize an array into plist format without the leak?
Regards, BX
So I edited the code and it now l开发者_JAVA技巧ooks like this but still a leak. It must be something esle. I included the loop after...
NSError *error = nil;
id plist;
plist = [NSPropertyListSerialization propertyListWithData:rawCourseArray options:/*unused*/0
format:NULL error:&error];
//NSArray *entries = (NSArray *)d;
NSArray *entries = (NSArray *)plist;
//for (eachCourse in rawCourseArray)
for (NSDictionary *entry in entries)
{
//LOOP
}
The method you are using is obsolete and is about to be deprecated according to the apple docs, you should use propertyListWithData:options:format:error:
instead
Linkage
There is no memory leak in that code. However, there is a potential crash. You should not It turns out that -release
the error object, because you do not own it.NSPropertyListSerialization
has a terrible API. Consider using the +[NSPropertyListSerialization propertyListWithData:options:format:error:]
variant instead.
Are you sure there's a memory leak here? What's the minimal amount of code you need to reproduce the leak?
精彩评论