• 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: mmalc crawford <email@hidden>
  • Date: Wed, 08 Oct 2008 09:55:30 -0700


On Oct 8, 2008, at 9:41 AM, Lee, Frederick wrote:

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;

No, that is not Apple-sanctioned best-practice.

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

Yes, for synthesized *instance variables*.

So if I understand correctly, what you're saying is that in my
particular circumstance (nonatomic),

'nonatomic' has nothing to do with it.

(and I'm synthesizing collections, strings & objects)
the preferred way is setting the 'self.iVar' to nil; per your example
below.
Correct?

No. I stated specifically "synthesized *instance variables*" and gave an example:

    @interface MyClass : NSObject
    {} // **** Note: no instance variables
    @property (retain) NSString *aString;
    @end

    @implementation MyClass
    @synthesize aString;
    -(void)dealloc {
          self.aString = nil;  // [aString release]; won't work
    }
    @end

If instead you had an explicit instance variable:

    @interface MyClass : NSObject {
         NSString *aString;
    }
    @property (retain) NSString *aString;
    @end

then you would use:

    @implementation MyClass
    @synthesize aString;
    -(void)dealloc {
        [aString release];
    }
    @end


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:
    • Synthesized versus Explicit *instance variables*.
      • From: "Lee, Frederick" <email@hidden>
    • Re: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ?
      • From: "Sean McBride" <email@hidden>
    • RE: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ?
      • From: "Lee, Frederick" <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>)
 >RE: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ? (From: "Lee, Frederick" <email@hidden>)

  • Prev by Date: NSIndexSet isEqual: sent to deallocated instance
  • Next by Date: RE: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ?
  • 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