unarchiveObjectWithFile retain / autorelease needed?

Posted by fuzzygoat on Stack Overflow See other posts from Stack Overflow or by fuzzygoat
Published on 2010-04-19T10:49:15Z Indexed on 2010/04/19 10:53 UTC
Read the original article Hit count: 483

Filed under:
|
|

Just a quick memory management question if I may ... Is the code below ok, or should I be doing a retain and autorelease, I get the feeling I should. But as per the rules unarchiveObjectWithFile does not contain new, copy or alloc.

-(NSMutableArray *)loadGame {
    if([[NSFileManager defaultManager] fileExistsAtPath:[self pathForFile:@"gameData.plist"]]) {
        NSMutableArray *loadedGame = [NSKeyedUnarchiver unarchiveObjectWithFile:[self pathForFile:@"gameData.plist"]];
        return loadedGame;
    } else return nil;
}

or

-(NSMutableArray *)loadGame {
        if([[NSFileManager defaultManager] fileExistsAtPath:[self pathForFile:@"gameData.plist"]]) {
            NSMutableArray *loadedGame = [[NSKeyedUnarchiver unarchiveObjectWithFile:[self pathForFile:@"gameData.plist"]] retain];
            return [loadedGame autorelease];
        } else return nil;
    }

gary

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iphone