PDA

View Full Version : dealloc versus @property(retain)




Thomas Harte
Jul 14, 2009, 04:04 AM
If I have a class with a property that is to be retained, e.g.:
@interface MRDemoClass: NSObject
{
NSString *name;
}

@property (retain) NSString *name;
@end

// [and, in the implementation file:]

@implementation MRDemoClass

@synthesize name;

@end
Need I manually ensure that any properties retained (such as 'name' in the above example) are released in my dealloc method? Is the answer different if I haven't implemented a dealloc method at all? This is all in a reference counted program, without the benefit of the new garbage collector.



Azrel
Jul 14, 2009, 04:25 AM
Read up on properties =)

@property (nonatomic, copy) NSString *name;

isaaclimdc
Jul 14, 2009, 04:44 AM
Yup. If you've got

@property (nonatomic, retain) NSString *name;

You need to use in the implementation, a dealloc:

[name release]