• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ? (From: "Lee, Frederick" <email@hidden>)

  • Prev by Date: Re: NSUndoManager f@*#ing up Core Data database
  • Next by Date: Where is close/cancel icon used in search field & Safari etc.
  • Previous by thread: Re: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ?
  • Next by thread: Re: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ?
  • Index(es):
    • Date
    • Thread