Re: memory management issue?
Re: memory management issue?
- Subject: Re: memory management issue?
- From: Chris Suter <email@hidden>
- Date: Sat, 2 Feb 2008 13:58:00 +1100
On 02/02/2008, at 7:38 AM, Mike Abdullah wrote:
- (void)setAddressBook
{
[book release];
[person release];
book = [[ABAddressBook sharedAddressBook] retain];
person = (ABPerson *)[[book recordForUniqueId:[self uid]] retain];
}
There's a big possible flaw here. What if the old and new book or
person objects are the same? You'll release the object, and if that
deallocs it, the next code will attempt to retain a dead object.
Admittedly in this particular case it's pretty unlikely, but it's
good general practice for accessor methods of all kinds.
There is no flaw here, or at least not the flaw you're suggesting.
[ABAddressBook sharedAddressBook] should always return a valid object,
as will recordForUniqueID. Your comment would make sense if something
was being passed as a parameter but it's not in this case.
The only possible flaw I can see is if sharedAddressBook: or
recordForUniqueId: were to throw exceptions (I don't know if they do
or not, I haven't checked), in which case book and person wouldn't be
valid. The solution here would be to to set them to nil after
releasing them or you could use garbage collection instead.
- Chris
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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