tags:

views:

85

answers:

2

hi friends.

Can anyone tell me the difference between [self.property release] and [property release] . I am asking this because in one of the view controller in my application ,i am doing [self.property release] and pushing this view controller in to the navigation stack ,when i pop this view controller its showing the error EXC_BAD_INSTRUCTION but when i do [property release] everything is working fine...? Can any one tell me where i am going wrong.. i am new to iphone app development.

+3  A: 

[property release] sends the release message to the property instance variable and is almost certainly what you want to do.

[self.property release] sends the release message to the object returned by self.property. The result of this will depend on whether the property is defined as assign / copy / retain and so basically you are probably releasing a different object to the one that you think you are.

Roger
Thanks roger...for your reply ..
A: 

The distinction is "self.myProperty" is an accessor method for the instance variable "myProperty". Accessor methods are generated by @synthesize, or can be defined explicitly as

-(Type*) myProperty; 
-(void) setMyProperty:(Type*)p;

So, assuming you've defined the accessor as (the key is retain)

@property (retain) Type* myProperty;

then

[myProperty release]; 
myProperty = nil;

is equivalent to

self.myProperty = nil;

In general, it's good practice to set released objects to nil so that you don't accidentally try to use (or over release) them.

There is no good reason to call [self.property release].

tomwhipple