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: Negm-Awad Amin <email@hidden>
- Date: Wed, 8 Oct 2008 18:23:52 +0200
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 (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
Amin Negm-Awad
email@hidden
_______________________________________________
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