Re: Correct memory management in -awakeAfterUsingCoder: ?
Re: Correct memory management in -awakeAfterUsingCoder: ?
- Subject: Re: Correct memory management in -awakeAfterUsingCoder: ?
- From: Graham Cox <email@hidden>
- Date: Tue, 5 May 2009 16:18:05 +1000
On 05/05/2009, at 3:57 PM, Greg Parker wrote:
Two answers:
1. Retain it. Conceptually, you're balancing the [self release] that
you did to the old-self. The old-self came in with one retain count
that was not your responsibility to release. That means the new-self
needs to go back out with one retain count that is not your
responsibility. So you should retain it before returning. Whatever
retain counts are held by the storage library are not sufficient by
themselves to make the accounting book balance.
Yes, that makes sense.
Strictly speaking, old-self's retain count could have been more than
one. But if that happens you've probably already fallen afoul of
answer number two:
2. Be very careful with replacing objects in -awakeAfterUsingCoder:.
It doesn't work in the general case, so you had better be sure
you're in a specific case that does work. See this thread for some
discussion:
http://www.cocoabuilder.com/archive/message/cocoa/2001/10/10/48468
(That's an old thread, but as far as I know the newer
NSKeyedArchiver didn't magically solve the problems.)
Thanks for the pointer - interesting read. I was somewhat aware of the
issue but that makes it much clearer. I'll check but I don't think I'm
running into that one.
thanks again,
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden