Line 1: First.h
Line 2: @property (nonatomic, retain) NSString *name;
Line 3: First.m
Line 4: @synthesize name;
Line 5: -(void)viewDidLoad()
Line 6: {
Line 7: name = [NSString stringWithString:@"Hello"];
Line 8: OR
Line 9: self.name = [[NSString alloc]initWithString:@"Hello"];
Line 10: OR
Line 11: }
Line 12:-(void)dealloc()
Line 13: {
Line 14: [name release];
Line 14: }
问题 1:
如果我遵循第 7 行,一切都很好,如果我使用第 9 行,则存在内存泄漏。据我所知, self 指向当前对象,如果我使用self.object
或根本object
没有区别。
问题2:如果我使用
@synthesize name = _name;
那么哪个是设置name的值,哪个是获取值呢?区别:
name = [NSString stringWithString:@"Hello"];
OR
self.name = [NSString stringWithString:@"Hello"];
OR
_name = [NSString stringWithString:@"Hello"];
问题 3:
如果我创建任何属性,是否需要在我分配的内存中分配显示内存泄漏?