• 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: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ?


  • Subject: Re: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ?
  • From: Jim Puls <email@hidden>
  • Date: Wed, 8 Oct 2008 08:59:44 -0700


On Oct 8, 2008, at 8:49 AM, Lee, Frederick wrote:

I've seen examples of using [myVar release]. But doesn't setting myVar
= nil does the same thing?




Which is the preferred way?

This is a point of more contention than you may realize. The former is, of course, equivalent to


[self setMyVar:nil];

which, as it calls a method on self during [self dealloc], is something frowned upon by many. It also triggers the KVO process, though if you're in dealloc, any KVO concerns should have finished long ago. On the other hand, it's a "purer" OO call style and allows you to stick with the property syntax as much as possible and lets you worry a bit less about memory management, which is nice.

YMMV, but you're probably safer doing [myVar release];. If you ever end up implementing your own -setMyVar: and it has side effects, there be demons ahead.

-> jp

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: 
 >In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ? (From: "Lee, Frederick" <email@hidden>)

  • Prev by Date: Re: Optimized pixel manipulation
  • Next by Date: Re: Optimized pixel manipulation
  • Previous by thread: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ?
  • Next by thread: Re: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ?
  • Index(es):
    • Date
    • Thread