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