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