• 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: How far with accessors?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How far with accessors?


  • Subject: Re: How far with accessors?
  • From: Marco Scheurer <email@hidden>
  • Date: Thu, 27 May 2004 16:09:29 +0200

On May 27, 2004, at 1:02 PM, Ondra Cada wrote:

Again, it's exactly the opposite: [foo release] is what makes unneeded
assumptions about the setter internal code. If you just use the setter
to remove the property, dealloc would work properly whatever the
accessors do (presumed they are not buggy, of course ;)). On the other
hand, had you use just [foo release] instead of the proper [self
setFoo:nil], the simplest change in accessors may break your code. For
example, you may decide to use the quicker (and less robust) accessor
pattern

-foo { return foo; }
-(void)setFoo:f { [foo autorelease]; foo=[f copy]; }

In the "your" way, you have to remember to change the your dealloc to
[foo autorelease].

I don't want to go back to the whole debate about the benefits (or lack of them) of autoreleasing accessors, but this doesn't make sense too me.

I don't necessarily disagree with sending setFoo:nil in dealloc, which could be considered a good practice, but otherwise I see no reasons why your dealloc should use autorelease instead of release. You may consider it anecdotical, but since reference counting was included in Foundation (1994?), I've *always* used [foo release] in dealloc, *always* used the quicker (and as you know in my opinion, not less robust) accessor, and *never* found a case where I should have used autorelease in dealloc! I also fail to see why this would be good in theory. I clearly see why it is bad, like wasting even more time in an operation (freeing memory) which often already takes way too long.

So I would even say that it stinks, and that if you need to do this there is something really bad in your code.

marco


Marco Scheurer
Sen:te, Lausanne, Switzerland http://www.sente.ch
_______________________________________________
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: How far with accessors?
      • From: Ondra Cada <email@hidden>
References: 
 >Fwd: How far with accessors? (From: Ondra Cada <email@hidden>)
 >Re: How far with accessors? (From: Jeff Biggus <email@hidden>)
 >Re: How far with accessors? (From: cricket <email@hidden>)
 >Re: How far with accessors? (From: Jeff Biggus <email@hidden>)
 >Re: How far with accessors? (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: Drag and stupid Drop in NSTableView
  • Next by Date: Re: "Manually" saving NSTableView info
  • Previous by thread: Re: How far with accessors?
  • Next by thread: Re: How far with accessors?
  • Index(es):
    • Date
    • Thread