NSDateインスタンス変数を1か月ずつインクリメントするメソッドを実装しようとしています。これでメモリ管理の問題が発生しています。(MallocScribbleとNSZombieEnabledを使用していて、次のメッセージを取得しています:-[CFDate copy]:割り当て解除されたインスタンス0x3d9dfa0に送信されたメッセージ)
私の質問は、日付をインクリメントするための最良の方法は何ですか?これが私のコードです:
NSDate *displayedMonthYear;
....
-(IBAction) nextMonth:(id)sender {
NSCalendar *calendar= [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
[dateComponents setMonth:1];
NSDate *prevDate = [displayedMonthYear copy];
[displayedMonthYear release];
displayedMonthYear = [calendar dateByAddingComponents:dateComponents toDate:prevDate options:0];
[prevDate release];
[dateComponents release];
[calendar release];
}
もともと私はprevDateコピーで少しはしていませんでしたが、次のようなことをしていました:
displayedMonthYear = [calendar dateByAddingComponents:dateComponents toDate:displayedMonthYear options:0];
しかし、そのアプローチではメモリがリークするのではないかと心配していました。ですから、これは日付の問題というよりもメモリ管理の問題だと思いますが、どんな助けでも素晴らしいでしょう-