• 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: mmalc crawford <email@hidden>
  • Date: Wed, 08 Oct 2008 09:26:03 -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?


To be clear, I assume you mean self.myVar = nil.
Neither, though "does the same thing".


Which is the preferred way?

Best practice is to use release directly, since this is lower overhead (especially if your accessor is atomic) and avoids the possibility of unwanted side-effects (especially if a subclass happens to override your set accessor).

The one place where you can't avoid this at the moment, though, is if you're using synthesised instance variables: you can't currently access the synthesised variable directly, so you will have to use the accessor method:

@interface MyClass : NSObject
{}
@property (retain) NSString *aString;
@end

@implementation MyClass
@synthesize aString;
-(void)dealloc {
    self.aString = nil;  // [aString release]; won't work
}


mmalc

_______________________________________________

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


  • Follow-Ups:
    • RE: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ?
      • From: "Lee, Frederick" <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: Where is close/cancel icon used in search field & Safari etc.
  • Next by Date: Re: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ?
  • Previous by thread: Re: 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