2010-11-27 15 views
0

これはよくあるケースです:
以下のコードでは、配列に追加される辞書の数は(通常どおり)データセットのサイズによって異なります。
したがって、各辞書を対応する 'release'ステートメントと照合することはできません。
配列を解放すると(deallocで)、すべての同封の辞書が解放されると思いますか?
それにもかかわらず、リークが発生します。どのようにそれを排除するには?CorePlotで使用される辞書で配列のリークを防ぐ方法

// -----myController.h---- 
@interface ExerciseGraphController : UIViewController <CPPlotDataSource>{   
    NSMutableArray   *plotDataForBar; 
} 
@property(readwrite, retain, nonatomic)NSMutableArray *plotDataForBar;     

// -----myController.m---- 
- ...getPlotData... { 

     //Solution 
     if (plotDataForBar){ 
      [plotDataForBar release]; 
     } 

     plotDataForBar = [[NSMutableArray array] init];        

     //for each item in plotDataForBar {      
      ...           //Populates plotDataForBar with dictionaries. 
      [plotDataForBar addObject: [NSDictionary dictionaryWithObjectsAndKeys:  // **LEAK** (on __NSCFDictionary, __NSArrayM, and _GeneralBlock16) 
       [NSDecimalNumber numberWithFloat:xF], [NSNumber numberWithInt:CPBarPlotFieldBarLocation],  
       [NSDecimalNumber numberWithFloat:yF], [NSNumber numberWithInt:CPBarPlotFieldBarLength], 
       nil]]; 
     }                
}              //Reads plotDataForBar in: 
- ...numberOfRecordsForPlot...{       //  Method required by CorePlot 
    return [plotDataForBar count];  
}   
- ...numberForPlot... {         //  "  "  "  " 
    ... 
    NSDecimalNumber *num = [[plotDataForBar objectAtIndex:index] objectForKey:[NSNumber numberWithInt:fieldEnum]]; 
    ...  
} 
- ...dealloc { 
    [plotDataForBar release]; 
    [super dealloc]; 
} 

答えて

1

は同様に多くのコードは、唯一の推測が欠落しています。

あなたはそのプロパティが既に設定されている場合は、「... ... getPlotDataを」のテスト、または古いインスタンスを解放するべきではないでしょうか。これは、このメソッドが呼び出されるたびに漏れています。

+0

それでした!上記のコードに「解決策」を追加しました。どうもありがとう! – sambaMan

関連する問題