• 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: memory management issue?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >memory management issue? (From: Steven Crosley <email@hidden>)
 >Re: memory management issue? (From: Chris Suter <email@hidden>)
 >Re: memory management issue? (From: Steven Crosley <email@hidden>)
 >Re: memory management issue? (From: j o a r <email@hidden>)
 >Re: memory management issue? (From: Steven Crosley <email@hidden>)
 >Re: memory management issue? (From: Mike Abdullah <email@hidden>)

  • Prev by Date: Re: new API for MacBook Air for Multi-touch trackpad?
  • Next by Date: Re: new API for MacBook Air for Multi-touch trackpad?
  • Previous by thread: Re: memory management issue?
  • Next by thread: Re: memory management issue?
  • Index(es):
    • Date
    • Thread