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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to