Am Mi,08.10.2008 um 17:49 schrieb Lee, Frederick:

Assuming the following:



@property(retain) myVar;

...

@synthesize myVar;



...



-(void) dealloc {

  // Can I use:

 self.myVar = nil;

// versus:

[myVar release];   //  ?

}





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



Which is the preferred way?
A never-ending story …

I prefer self.prop = nil (self setProp:nil]).

Some ideas:

1. Disadvantage: In a logical sense, you are on to deconstruct the object. So you can say, that it is not valid anymore and you are not allowed to send $anything to that object. I think, that you are inside the class and can handle this.

2. Disadvantage: You have to take care: side-effects! Think of undoing inside the setter. You probably do not want to register this operation for undoing. (Undo would fail, because the object is deconstructed.)

3. Advantage: Sometimes to care for consistency of your model inside a setter. And in this case I want to have this work done on deconstruction. If you just release it, maybe this work is never done by accident.

In must, most cases, especially when using @synthesize, it does not matter …

Cheers





Ric.





_______________________________________________

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/negm-awad%40cocoading.de

This email sent to [EMAIL PROTECTED]

Amin Negm-Awad
[EMAIL PROTECTED]




_______________________________________________

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