• 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: "Lee, Frederick" <email@hidden>
  • Date: Wed, 8 Oct 2008 12:41:44 -0400
  • Thread-topic: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ?

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@hidden]
Sent: Wednesday, October 08, 2008 11:26 AM
To: Lee, Frederick
Cc: email@hidden
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 (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

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

  • Prev by Date: Re: Why does toolbar use validation and not enable/disable?
  • Next by Date: NSIndexSet isEqual: sent to deallocated instance
  • 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