Skip navigation.
 
mlRe: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ?
FROM : mmalc crawford
DATE : Wed Oct 08 18:55:30 2008

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

Related mailsAuthorDate
mlIn dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ? Lee, Frederick Oct 8, 17:49
mlRe: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ? Jim Puls Oct 8, 17:59
mlRe: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ? Ron Lue-Sang Oct 8, 18:06
mlRE: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ? Lee, Frederick Oct 8, 18:09
mlRe: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ? Negm-Awad Amin Oct 8, 18:23
mlRe: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ? mmalc crawford Oct 8, 18:26
mlRe: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ? Negm-Awad Amin Oct 8, 18:26
mlRE: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ? Lee, Frederick Oct 8, 18:41
mlRe: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ? mmalc crawford Oct 8, 18:55
mlRE: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ? Lee, Frederick Oct 8, 18:58
mlRe: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ? Sean McBride Oct 8, 19:16
mlRe: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ? mmalc crawford Oct 8, 19:21
mlSynthesized versus Explicit *instance variables*. Lee, Frederick Oct 8, 19:44
mlRe: Synthesized versus Explicit *instance variables*. Charles Steinman Oct 8, 20:20
mlRe: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ? Sean McBride Oct 9, 01:44
mlRe: In dealloc(): ref @property, Can I use "<property object> = nil; " vs "[<property object> release]; " ? mmalc crawford Oct 9, 02:46