Re: Solved [Q] Why unsolicited dealloc in NSKeyedUnarchiver?
Re: Solved [Q] Why unsolicited dealloc in NSKeyedUnarchiver?
- Subject: Re: Solved [Q] Why unsolicited dealloc in NSKeyedUnarchiver?
- From: John Randolph <email@hidden>
- Date: Tue, 27 Apr 2004 14:46:26 -0700
On Apr 20, 2004, at 4:32 PM, Peter.Teeson wrote:
With the help of someone in a newsgroup I have solved htis (as well as
gained a mite more understanding.
I modified this method to release and retain (as was hinted by two
gentle persons)
-(id)initWithCoder:(NSCoder *)coder {
self = [super init];
passwordRecs = [[NSMutableArray alloc] init];
[self addPasswordRecord];
if ([coder allowsKeyedCoding]) {
[passwordRecs release]; // avoid leak
passwordRecs = [coder decodeObjectForKey:@"passwordRecs"];
[passwordRecs retain]; // retain auto-released object
}
return self;
}
What you've got above will work, but you have two unnecessary lines of
code there. There's no need to create and then release an array for
passwordRecs, since you're going to get one from -decodeObjectForKey:.
Try:
-(id)initWithCoder:(NSCoder *)coder {
self = [super init];
[self addPasswordRecord];
if ([coder allowsKeyedCoding]) {
passwordRecs = [coder decodeObjectForKey:@"passwordRecs"];
[passwordRecs retain]; // retain auto-released object
}
return self;
}
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.