0
这是一种常见情况:
在下面的代码中(简体),添加到数组的字典数量根据数据集的大小(如往常一样)而不同。
因此,不可能将每个字典与相应的“发布”声明进行匹配。
我认为释放数组(在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];
}
就是这样!我在上面的代码中添加了'解决方案'。非常感谢! – sambaMan 2010-11-27 22:26:44