My environment is certain '...apple-based mobile phone' that is
nonatomic.

So all my iVars are accessed via:
@property(nonatomic, retain) iVar; // array, dictionary, etc. <--
collections & objects.

Also, I'm not subclassing these properties.

I've seen examples of releasing the iVars & setting their pointers to
nil.

So I figure, using the self.iVar = nil;

So you say:
1) use the [iVar release] directly; yet
2) use the "self.iVar = nil" approach for 'synthesized instance
variables.'

So if I understand correctly, what you're saying is that in my
particular circumstance (nonatomic),
(and I'm synthesizing collections, strings & objects)
the preferred way is setting the 'self.iVar' to nil; per your example
below.

Correct?

Ric.



-----Original Message-----
From: mmalc crawford [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, October 08, 2008 11:26 AM
To: Lee, Frederick
Cc: cocoa-dev@lists.apple.com
Subject: Re: In dealloc(): ref @property, Can I use "<property object> =
nil; " vs "[<property object> release]; " ?


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