views:

34

answers:

0

I have a custom object that I am using NSKeyedArchiver to convert to NSData so my custom object implements the NSCoding protocol. But when I run the Instruments tool, it tells me that my initWithCoder method has a number of leaked NSCFString objects inside initWithCoder.

What is the correct way to implement the NSCoding protocol?

My class:

@interface EventProfile : NSObject <NSCoding>
    NSString *eventTitle;   
    NSString *groupName;                                
@end
@implementation EventProfile

// NSCoding methods
-(id) initWithCoder:(NSCoder *)decoder
{
    if (self = [super init])
    {
        eventTitle = [[decoder decodeObjectForKey:@"eventTitle"] retain];
        groupName = [[decoder decodeObjectForKey:@"groupName"] retain];
    }

    return self;
}
-(void) encodeWithCoder:(NSCoder *)encoder
{
    [encoder encodeObject:self.eventTitle forKey:@"eventTitle"];
    [encoder encodeObject:self.groupName forKey:@"groupName"];  
}
// Memory management
- (void)dealloc
{           
    [eventTitle release];
    [groupName release];

    [super dealloc];
}    

@end