Iphone 如何使用CorePlot使用的字典防止数组泄漏

Iphone 如何使用CorePlot使用的字典防止数组泄漏,iphone,objective-c,memory-leaks,ios4,core-plot,Iphone,Objective C,Memory Leaks,Ios4,Core Plot,这是一种常见情况: 在下面的代码(简化)中,添加到数组中的字典的数量取决于数据集的大小(通常)。 因此,不可能将每个词典与相应的“release”语句相匹配。 我假设释放数组(在dealloc中)将释放其所有附带的字典? 然而,它会产生泄漏。如何消除它 // -----myController.h---- @interface ExerciseGraphController : UIViewController <CPPlotDataSource>{ NSMu

这是一种常见情况:
在下面的代码(简化)中,添加到数组中的字典的数量取决于数据集的大小(通常)。
因此,不可能将每个词典与相应的“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]; 
}
/----myController.h----
@接口ExerciseGraphController:UIViewController{
NSMUTABLEARRY*plotDataForBar;
}
@属性(读写、保留、非原子)NSMUTABLEARRY*plotDataForBar;
//----myController.m----
-…获取绘图数据。。。{
//解决方案
if(plotDataForBar){
[plotDataForBar发布];
}
plotDataForBar=[[NSMutableArray]init];
//对于plotDataForBar{
…//使用字典填充plotDataForBar。
[plotDataForBar addObject:[NSDictionary Dictionary With Objects and Keys://**LEAK**(在u NSCFDictionary、u nsarray和_GeneralBlock16上)
[NSDECIMALNUMBERWITHFLOAT:xF],[NSNUMBERWITHIT:CPBARPLOTTFIELDBARLOCATION],
[NSDecimalNumber numberWithFloat:yF],[NSNumber NUMBERWITHIT:CPBARPLOTTFIELDBARLENGTH],
无]];
}                                                            
}//在以下位置读取plotDataForBar:
-…numberOfRecordsForPlot…{//CorePlot所需的方法
返回[plotDataForBar计数];
}           
-…号码或号码。。。{                                 //      "       "     "      "  
... 
NSDecimalNumber*num=[[plotDataForBar objectAtIndex:index]objectForKey:[NSNumber numberwhithint:fieldEnum]];
...     
}
-…解除锁定{
[plotDataForBar发布];
[super dealoc];
}

缺少的代码太多,只能猜测:

如果已经设置了该属性,是否应该在“…getPlotData…”中进行测试,或者释放旧实例?每次调用此方法时都会发生泄漏