|
What is the persistence of a DrawArea object? |
Posted by DC Kelley on Aug-25-2011 01:46 |
|
What is the persistence of a DrawArea() object?
In a fragment like the below, where I alocated on the heap
should I be deleting this object after the set data symbol call?
If not as below, then when? Or does CD do this for me.
DrawArea *d = new DrawArea();
d->setSize(c->getPlotArea()->getWidth(),
c->getPlotArea()->getHeight(),Chart::Transparent);
d->polygon(IntArray(&(x[0]),ptCnt),
IntArray(&(y[0]),ptCnt),
colorLine, colorFill);
// assign this unique lane symbol (its path) to the correct lane data point
layer->getDataSet(0)->setDataSymbol(d);
// release memory
if (d != NULL) delete d; // <<<<-- SHOULD THIS OCCUR HERE???
if (x != NULL) delete [] x;
if (y != NULL) delete [] y;
I know I can kill the X-Y data sets once once the call is made,
I am less clear about draw area object. |
Re: What is the persistence of a DrawArea object? |
Posted by Peter Kwan on Aug-25-2011 02:22 |
|
Hi DC Kelley,
Our suggestion is to delete the XYChart first. After that, you can assume that the DrawArea will no longer be used by the XYChart (as the XYChart has already been deleted), and so you can safely delete the DrawArea.
Unlike the data, the XYChart does not keep a deep copy of the DrawArea object, and it is not documented how and when the DrawArea object will be used by the XYChart. So the safest method is to delete the XYChart first, then the DrawArea.
ChartDirector will not automatically delete the DrawArea for you. It is because from the XYChart point of view, it is not known how you created the DrawArea in the first place (it can be in the stack as well as in the heap). This arrangement also allows you to use the same DrawArea in multiple charts.
Hope this can help.
Regards
Peter Kwan |
Re: What is the persistence of a DrawArea object? |
Posted by DC Kelley on Aug-25-2011 08:44 |
|
Okay I can live with that, will just make the drawing area a global we dump after every rendering. Now that I have one image shared for multiple objects (before I had created one per - very bad idea), the speed is back as well as my memory profile. I have yet to have any problem with the delete calls but will do as you suggested. |
|