dealloc versus @property(retain)

Discussion in 'Mac Programming' started by Thomas Harte, Jul 14, 2009.

  1. macrumors 6502

    Joined:
    Nov 30, 2005
    #1
    If I have a class with a property that is to be retained, e.g.:
    Code:
    @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.
     
  2. macrumors regular

    Azrel

    Joined:
    Jun 8, 2005
    #2
    Read up on properties =)

    @property (nonatomic, copy) NSString *name;
     
  3. macrumors 6502

    isaaclimdc

    Joined:
    Jun 28, 2009
    Location:
    Pittsburgh, PA
    #3
    Yup. If you've got

    Code:
    @property (nonatomic, retain) NSString *name;
    You need to use in the implementation, a dealloc:

    Code:
    [name release]
     

Share This Page