Re: [Q] Why unsolicited dealloc in NSKeyedUnarchiver?
Re: [Q] Why unsolicited dealloc in NSKeyedUnarchiver?
- Subject: Re: [Q] Why unsolicited dealloc in NSKeyedUnarchiver?
- From: Chris Hanson <email@hidden>
- Date: Mon, 19 Apr 2004 23:06:21 -0700
On Apr 19, 2004, at 7:35 PM, Peter.Teeson wrote:
In trying to add Open Recent support to MyDocument app everything is
working fine with the exception of an unsolicited call to dealloc by
NSKeyedUnarchiver. Any ideas where this is coming from and moreover
why? I'm confused. TIA for your help... Peter
From MyDocument
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
passwordRecords = [NSKeyedUnarchiver unarchiveObjectWithData:data];
return YES;
}
You should be retaining passwordRecords, since you're getting it from a
method that isn't an alloc or copy and you presumably want to keep it
around.
From PasswordsDataSource designated initializer
-(id)initWithCoder:(NSCoder *)coder {
self = [super init];
passwordRecs = [[NSMutableArray alloc] init];
[self addPasswordRecord];
if ([coder allowsKeyedCoding]) {
passwordRecs = [coder decodeObjectForKey:@"passwordRecs"];
}
return self;
}
The idiom is to check for a nil result from [super init]. Also, you're
leaking an NSMutableArray, since you +alloc and then -init one, assign
it to passwordRecs, and then assign an autoreleased object to
passwordRecs.
You should also make sure the memory management is correct in your
accessor methods. While it may not be in the above code, it sounds
like your memory management is a little out of whack.
-- Chris
--
Chris Hanson <email@hidden>
http://www.livejournal.com/users/chanson/
_______________________________________________
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.