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

Re: Properties and memory management


  • Subject: Re: Properties and memory management
  • From: Negm-Awad Amin <email@hidden>
  • Date: Tue, 5 Aug 2008 12:42:03 +0200




Am Di,05.08.2008 um 12:05 schrieb mmalc crawford:


On Aug 5, 2008, at 3:00 AM, mmalc crawford wrote:

No, this is not the case -- Ken's reply was correct. If you use automatic KVO notifications, your accessors will still have side effects.

Although I should add that of course by the time you reach dealloc you should not have observers...
That is, what I wrote. (accidentally not to the list)

The general point still stands, though.
For what reason?

The correct pattern is:
Set instance variables directly in init methods, and release them directly in dealloc.


On Aug 5, 2008, at 2:57 AM, Uli Kusterer wrote:

Though I vaguely remember getting lectured by someone about why it's better to *always* use the accessors a while ago ... wish I remembered what the reasoning behind that was, and why I thought it might be a good idea to follow that, but OTOH didn't follow it :-/

Other than in init, you should always use accessors to set values because:
(a) The accessors might have side-effects (such as emitting KVO change notifications) that your application relies on;
(b) Accessors are typically the best place to put memory management code. If you push "all" your memory management to accessors, then you're much less likely to make a mistake somewhere along the line...
Sic!
Why does this reasons do not apply to -init and -dealloc?

The only reason for direct accesses are side-effects in the setters, which you do not want to apply at -deallocation time. I think, that this is rare.

Amin



mmalc


Amin Negm-Awad email@hidden




Amin Negm-Awad email@hidden




_______________________________________________

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: 
 >Properties and memory management (From: Mike Manzano <email@hidden>)
 >Re: Properties and memory management (From: Jonathan Hess <email@hidden>)
 >Re: Properties and memory management (From: Uli Kusterer <email@hidden>)
 >Re: Properties and memory management (From: "Ken Ferry" <email@hidden>)
 >Re: Properties and memory management (From: Negm-Awad Amin <email@hidden>)
 >Re: Properties and memory management (From: mmalc crawford <email@hidden>)
 >Re: Properties and memory management (From: mmalc crawford <email@hidden>)

  • Prev by Date: Localize App Title?
  • Next by Date: Re: Localize App Title?
  • Previous by thread: Re: Properties and memory management
  • Next by thread: Re: Properties and memory management
  • Index(es):
    • Date
    • Thread