Это обычный случай:
В приведенном ниже коде (упрощенно) количество словарей, добавляемых в массив, зависит от размера набора данных (как обычно).
Поэтому невозможно сопоставить каждый словарь с соответствующим оператором «release».
Я предполагаю, что освобождение массива (в dealloc) освободит все его вложенные словари?
Тем не менее, это вызывает утечку. Как это устранить?
// -----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];
}