The Leaks instrument tells me that I have a memory leak when I use initWithCoder. For example, here is the pattern of what I am doing (somewhat pseudo):
Class.h
{
MyObject *myObject;
}
@property (nonatomic, retain) MyObject *myObject;
Class.m
@synthesize myObject
-(void)dealloc{
[myObject release];
[super release];
}
-(id)initWithCoder

NSCoder *)decoder{
if (self = [super init]{
self.myObject = [decoder decodeObjectForKey:@"MyObject"];
}
return self;
}
Leaks reports a leak of type NSCFString on the line;
self.myObject = [decoder decodeObjectForKey:@"MyObject];
As I understand it, initWithCoder returns an autoreleased object. Since I immediately assign that value to the myObject property, which is specified as (nontoxic, retain) in the property definition, I retain the autoreleased object through the setter method of the myObject property. The myObject is then released in the dealloc method. I don't understand where the leak is if I understand the sequence correctly. Also why is it reported as a NSCFString when the type is MYObject?
Any thoughts would be appreciated.