On Nov 19, 2008, at 2:29 PM, mmalcolm crawford wrote:
> You send a release message to instance variables for which there is a
> corresponding retain or copy property.

which is why I originally said:
>>> (This is the one thing I hate the *most* about properties - they  
>>> really feel glued on, at this point, rather than being a language
feature  
>>> that the "whole compiler" knows about)

Most of the time you are supposed to think in terms of abstract
properties (so that KVO will work) but in your dealloc, you need to fall
back to worrying about the instance variables used to *implement* those
properties.

If you accept the default behaviour and name your properties the same as
your instance variables, then you don't necessarily notice that it's the
instance variables you clean up.  Its really easy to think that

- (void) frammitz { [something foobar]; }

        and

- (void) frammitz { [self.something foobar]; }

are *identical* and they are not.  The Objective-C designers choice of
'.' syntax, which just *screams* structure-member-access to anyone with
C++ experience makes it even more confusing for those of us who have a
multi-language background.

The phrase "for which there is a *corresponding* ... property" is the
one I still need to repeat to myself over and over.  To a certain
extent, properties are orthogonal to instance variables; you can choose
to implement properties via equivalently named instance variables but
its not a given that you have to.  And you can have instance variables
without property definitions.

The @property declaration, where you use an alternate name, seems like
an area for confusion.

@property (nonatomic,retain) NSObject *xxx;
...
@synthesize xxx=_yyy;
...

not only defines accessors for a property called 'xxx', but also defines
the memory retention contract for the instance variable '_yyy'.  In the
past, you need only look in your .m file to determine how you needed to
clean up your instance variables irrespective of the public interface
they define in the .h file.  Now, you need to look in both the .h and
the .m 

As someone else remarked, @synthesize does *most* but not all of the
job, if its job is to 'provide the implementation of the property'.  The
reality is that its job is only to 'provide the *accessors* for the
property' which it does do completely.  And it does seem like having one
more hack, perhaps

- (void)dealloc
{
        @release xxx;
        [super dealloc];
}

would make me feel like the feature (properties) was actually complete.

Jeff Laing <[EMAIL PROTECTED]>
------------------------------------------------------------------------
------
The lessons of history teach us - if they teach us anything - that
nobody learns the lessons that history teaches us.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to