我經常看到這樣的:而不是爲什麼要製作臨時對象,將它們設置爲變量,然後釋放它們?
NSArray *tmpArr = [[NSArray alloc] initWithObjects:@"Info", nil];
self.userInfo = tmpArr;
[tmpArr release];
:
self.userInfo = [[NSArray alloc] initWithObjects:@"Info", nil];
有誰知道爲什麼上面的代碼示例是更受歡迎?內存管理比第二個更正確嗎?
完全相同的副本(http://stackoverflow.com/questions/7017046/objective-c-newbie-question-about -allocation-保留和釋放) –