2011-04-07 106 views
1

這個問題困惑了我很多。 selectedDate也是NSDate的一個對象。 如果我刪除mark1上的行,該項目將正常運行。如果不是,則在我調用此方法後,此項目將會關閉。 問題在哪裏? 非常感謝!我是否正確釋放對象?

NSDate *selectedData_c = [self.selectedDate dateByAddingTimeInterval:60 * 60 * 8]; 
self.label = (UILabel *)[nibLoadedCell viewWithTag:1]; 
label.text = [NSString stringWithFormat:@"%@-%@-%@",[[selectedData_c description] substringWithRange:yearRange],[[selectedData_c description] substringWithRange:monthRange],[[selectedData_c description] substringWithRange:dayRange]]; 
[selectedData_c release];   // mark1 
return cell; 

回答

3

您不需要釋放它,它是一個autorelease對象。通常你只發布你自己編輯的東西。

1
selectedData_c 

無需發佈爲dateByAddingTimeInterval方法將返回autorelease對象。

1

號「dateByAddingTimeInterval」不包含單詞頁頭,複製,保存,或mutableCopy。因此,您不對該內存負責。這是一個客觀的命名標準。

請注意,如果您希望數據在發佈字符串後繼續存在,則應複製它;通過合同,你對該記憶沒有任何責任,但也不能保證它會超出賦予給你的對象的範圍。

0

您不應該release它,它是autorelease'd。請閱讀Apple發佈的Memory Management Rules。他們有意義,他們讓在iOS平臺上的內存管理很容易。