0

Possible Duplicate:
Is releasing memory of Objective-c 2.0 properties required?

For example:

@interface DataMode : NSObject {
    NSString * name;
}

@property (nonatomic, retain) NSString * name;

@end

Will the compiler automatically add [name release] to -dealloc?

- (void) dealloc
{
   [name release];    // if we  don't add it , will the compiler add "[name release]"???
   [super release];     

}
Community
  • 1
  • 1
user961298
  • 11
  • 2
  • 3
    Note that it should be `[super dealloc]` instead of `[super release]`. –  Sep 24 '11 at 08:03

2 Answers2

5

It depends on which memory management scheme you’re using:

  • With garbage collection, you don’t need to release the instance variable that backs the declared property — the garbage collector automatically does that. In fact, you wouldn’t be defining a -dealloc method at all even if you need to do other tasks upon deallocation: the garbage collector sends -finalize instead of -dealloc;

  • With automatic reference counting (ARC), you wouldn’t define that -dealloc method. ARC will automatically release the instance variable that backs the declared property. You can define a -dealloc method to do other housekeeping tasks if needed but you won’t send [super dealloc];

  • With manual memory management, you need to manually release the instance variable that backs the declared property and then send [super dealloc].

  • Good summery, and I'm really anticipating changing everything to the latest technology of the three - ARC. – Eiko Sep 24 '11 at 08:18
0

Since you are adding or rather creating name its your responsibility to release it. So you need to add [name release] in dealloc and also in ViewDidUnLoad use name = nil.

ObjectiveC has garbage collection but in iOS garbage collection part has been stripped out. So allocation, deallocation, retain etc. you need to be aware of...

Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264