Instrumentsが検出したリークを修正する際に問題が発生しています。私はNSCalendar
のdateByAddingComponents:toDate:options:
メソッドを使ってループ内の日付を減らそうとしており、NSDate
個のオブジェクト(正確には49個)のリークが続いています。私はいくつかの異なる方法で、このリークを修正しようとしたが、それは最初の場所で漏れた理由を私は理解していないとして、私は本当に持っているループ内の日付を減らしながらリークする
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
// Get current date
NSDate *date = [NSDate date];
// Create an NSDateComponents object that will be used to decrement the date
NSDateComponents *decStep = [[NSDateComponents alloc] init];
[decStep setDay:-1];
for (NSUInteger i = 49; i >= 0 ; i--)
{
// Insert the date object in an array
[self.fooArray insertObject:date atIndex:0];
// Decrement the date
date = [gregorian dateByAddingComponents:decStep toDate:date options:0];
}
// Release calendar and date components objects
[decStep release];
[gregorian release];
:ここ
は私のコードは次のようになります私が何をしているのか分かりません。 NSAutoreleasePool
を使用しないことを望んでいることを知って、この問題を解決するのに役立つ手がかりはありますか?
まあ、あなたは両方とも正しい!漏れは、日付からではなく、配列から来ていた。 'self.fooArray'はcopyの代わりにretainと宣言され、コピーするように変更した後、一時配列を使用して、' self.fooArray = tpmArray'の後に解放しなければなりませんでした。ありがとう! – Axel
私は、 'NSDate'のファクトリメソッド' date'を使っていて、 'date'変数を再利用していたという事実は私に間違った方向に見えていたと思います。 – Axel