What happens exactly when I set the nil property in the dealloc method?

Example

-(void)dealloc { self.myOutletProperty = nil; [super dealloc]; } 

I assume that the type of virtual setter will be called. But what is going on here? Why is zero?

+1
objective-c iphone cocoa-touch
Apr 24 '09 at 10:06
source share
4 answers

You should know that a property is just syntactic sugar.

eg:

 @property(nonatomic, retain) NSString *myString; 

converted to

 - (NSString*)myString { return myString; } - (void)setMyString:(NSString*)newString { if (myString != newString) { [myString release]; myString = [newString retain]; } } 

so if you declare @property in something way this actually frees up

+12
Apr 24 '09 at 11:33
source share
— -

1.If the property type is “copy” or “hold”, then

self.myOutletProperty = nil; this is the same as [myOutletProperty release];

2. If the property type is "assigns", then

self.myOutletProperty = nil; nothing to do

+7
Apr 24 '09 at 11:25
source share

One thing to keep in mind is that even if setting your property to nil will work fine, I recommend calling [object release] in your dealloc method. That way, you'll be safe if you write your own setter method that references another ivar (which may have already been released), or you have KVO notifications registered in this property somewhere else.

+2
Apr 24 '09 at 21:17
source share

Nil is the same as null, but for objects. This means the absence of an object.

The Dot syntax is similar to calling [self setMyOutletProperty: nil].

So, you just remove the object from some property. The meaning depends on what kind of property you are talking about.

+1
Apr 24 '09 at 10:23
source share



All Articles