I am building an application where I am using CorePlot libraries to show graphs.
I have a tableView and when a cell is tapped it shows the relevant chart in a detailed view controller.
Now While testing my app in instrument i found that when the chart loads there is an increase in memory allocation.
In my detailViewController I am releasing everything that I am retaining.
I have CPXYGraph *graph defined in my .h file
and in a function in .m I am adding a plot to my graph object
i.e.
CPScatterPlot *boundLinePlot2 = [[[CPScatterPlot alloc] init] autorelease];
boundLinePlot2.identifier = @"My Plot2";
boundLinePlot2.dataLineStyle.miterLimit = 1.0f;
boundLinePlot2.dataLineStyle.lineWidth = 1.0f;
boundLinePlot2.dataLineStyle.lineColor = [CPColor yellowColor];
boundLinePlot2.dataSource = self;
// Add plot symbols
CPLineStyle *symbolLineStyle2 = [CPLineStyle lineStyle];
symbolLineStyle2.lineColor = [CPColor yellowColor];
symbolLineStyle2.lineWidth = 1.0f;
CPPlotSymbol *plotSymbol2 = [CPPlotSymbol ellipsePlotSymbol];
plotSymbol2.fill = [CPFill fillWithColor:[CPColor yellowColor]];
plotSymbol2.lineStyle = symbolLineStyle2;
plotSymbol2.size = CGSizeMake(0.2, 0.2);
boundLinePlot2.plotSymbol = plotSymbol2;
// Set plot delegate, to know when symbols have been touched
// We will display an annotation when a symbol is touched
boundLinePlot2.delegate = self;
boundLinePlot2.plotSymbolMarginForHitDetectionX = 25.0f;
boundLinePlot2.plotSymbolMarginForHitDetectionY = 400.0f;
[graph addPlot:boundLinePlot2];
Now My question is if I do something like [graph removePlot:boundLinePlot2] when going back to my mainViewController, does it will make any difference in my memory allocation problem and if not then when we should be using removePlot property
Each plot caches its own data after loading it from the datasource, so that’s probably most of the allocation increase you’re seeing.
Remove the graph from its hosting view and release it to reclaim the memory when you’re done with it. The
-removePlot:method only removes the given plot from the graph. That will free up some memory as long as you don’t retain the plot somewhere else.