Freeing @property (copy) instance variables?

I'm sure I'm doing it right, but just want to check. I have two instance variables that have accessors created via @property. In my dealloc (for the same object), I free these objects.

@property(copy) NSString *firName; @property(copy) NSString *surName; -(void)dealloc { NSLog(@"_deal: %@", self); [firName release]; [surName release]; [super dealloc]; } 

Gary

+6
objective-c cocoa
source share
3 answers

Yes, that's right.

the implementation of the property will call release at the previous value before copying the new value, therefore the only memory management that you have to worry about is that you are freed in the dealloc method that you do.

+6
source share

It looks right. I usually used nonatomic , retain with NSString properties, though ...

EDIT: copy this.

0
source share

It is right. Remember the memory ownership policy. Since you are using a copy, you get ownership of the object in the same way as if you were using conservation, so you release it after completion.

0
source share

All Articles