• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Solved [Q] Why unsolicited dealloc in NSKeyedUnarchiver?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: Solved [Q] Why unsolicited dealloc in NSKeyedUnarchiver?
      • From: "Peter.Teeson" <email@hidden>
References: 
 >[Q] Why unsolicited dealloc in NSKeyedUnarchiver? (From: "Peter.Teeson" <email@hidden>)
 >Re: [Q] Why unsolicited dealloc in NSKeyedUnarchiver? (From: "Louis C. Sacha" <email@hidden>)
 >Re: [Q] Why unsolicited dealloc in NSKeyedUnarchiver? (From: "Peter.Teeson" <email@hidden>)
 >Re: [Q] Why unsolicited dealloc in NSKeyedUnarchiver? (From: Shawn Erickson <email@hidden>)
 >Re: Solved [Q] Why unsolicited dealloc in NSKeyedUnarchiver? (From: "Peter.Teeson" <email@hidden>)

  • Prev by Date: Re: Is Concatenation that complex?
  • Next by Date: Re: Transparency?
  • Previous by thread: Re: Solved [Q] Why unsolicited dealloc in NSKeyedUnarchiver?
  • Next by thread: Re: Solved [Q] Why unsolicited dealloc in NSKeyedUnarchiver?
  • Index(es):
    • Date
    • Thread