BX69
BX69

Reputation: 431

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 looks 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
        }

Upvotes: 2

Views: 3414

Answers (2)

Dave DeLong
Dave DeLong

Reputation: 243146

There is no memory leak in that code. However, there is a potential crash. You should not -release the error object, because you do not own it. It turns out that 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?

Upvotes: 0

Zaky German
Zaky German

Reputation: 14334

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

Upvotes: 1

Related Questions