1
@interface SearchViewController : UIViewController<UITableViewDelegate, UITableViewDataSource> {
NSMutableDictionary * results;
}
@property (nonatomic, retain) NSMutableDictionary * results;
和@synthesize结果;在.M由NSMutableDictionary发布/保留
此代码将崩溃
NSMutableDictionary * md = [[NSMutableDictionary alloc] init];
results = md;
[md release];
这个代码是OK
NSMutableDictionary * md = [[NSMutableDictionary alloc] init];
results = md;
它清楚,我认为指针犯规得到保留,但我不知道为什么,我做了水手。错误?
所以基本上我可以做结果= [[NSMutableDictionary alloc] init];并在viewDidUnload做[结果发布];一切都会好起来的(iam不使用=任何地方)?如果我在这种情况下甚至没有声明属性,那就更好了......对吗? – 2011-04-03 20:33:24
是的,使用财产是没有必要的。 Objective-C 2.0之前有一段时间没有任何属性。虽然我不得不承认,但我经常使用它们,它们帮助我正确地进行内存管理。 – 2011-04-03 20:40:43